You can define your own slot (any python called) and connect it to the signal, and then call other slots from this slot.
class Example(QWidget): def __init__(self): super().__init__() self.initUI() def printLabel(self, str): print(str) def logLabel(self, str): '''log to a file''' pass @QtCore.pyqtSlot(int) def on_sld_valueChanged(self, value): self.lcd.display(value) self.printLabel(value) self.logLabel(value) def initUI(self): self.lcd = QLCDNumber(self) self.sld = QSlider(Qt.Horizontal, self) vbox = QVBoxLayout() vbox.addWidget(self.lcd) vbox.addWidget(self.sld) self.setLayout(vbox) self.sld.valueChanged.connect(self.on_sld_valueChanged) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('Signal & slot')
In addition, if you want to define your own signals, they must be defined as class variables.
class Example(QWidget): my_signal = pyqtSignal(int)
The pyqtSignal arguments determine the types of objects that will be emit on this signal, so in this case you could do
self.my_signal.emit(1)
emit can be overridden to send specific signal values to a slot function. It is not yet clear why I will need to send different values from previously existing signal methods.
Normally you should not emit embedded signals. You only need to generate the signals that you define. When defining a signal, you can define different signatures with different types, and the slots can choose which signature they want to connect to. For example, you can do this
my_signal = pyqtSignal([int], [str])
This will determine the signal with two different signatures, and the slot can connect to one of
@pyqtSlot(int) def on_my_signal_int(self, value): assert isinstance(value, int) @pyqtSlot(str) def on_my_signal_str(self, value): assert isinstance(value, str)
In practice, I rarely overload signal signatures. Normally, I would simply create two separate signals with different signatures, and not overload the same signal. But it exists and is supported in PyQt because Qt has signals that are overloaded in this way (e.g. QComboBox.currentIndexChanged )