[PySide] New Style Signal/Slot
Aaron Richiger
a.richi at bluewin.ch
Tue Jul 17 14:43:10 CEST 2012
Hello Tim!
Signals and slots are much more intuitive with PySide. One possible way
showing some signals and slots in action is the code below!
Cheers, Aaron!
#########################################################
import sys
from PySide.QtGui import *
from PySide.QtCore import *
class SignalSlotDemonstrator(QWidget):
signalButtonPressed = Signal(str)
signalButtonPressed2 = Signal(str)
def __init__(self, parent=None):
super(SignalSlotDemonstrator, self).__init__(parent)
self.pb = QPushButton('Click me to emit a signal', self)
self.pb.clicked.connect(self.emitSignalPressed)
self.pb.clicked.connect(lambda:
self.signalButtonPressed.emit('with lambda'))
self.resize(300, 200)
def emitSignalPressed(self):
self.signalButtonPressed.emit('with helper method')
if __name__ == '__main__':
def testSlotButtonPressed(word):
print 'got signal with parameter:', word
app = QApplication(sys.argv)
w = SignalSlotDemonstrator()
w.show()
w.signalButtonPressed.connect(testSlotButtonPressed)
w.signalButtonPressed2.connect(testSlotButtonPressed)
sys.exit(app.exec_())
Am 17.07.2012 14:25, schrieb Tim Doty:
> I started with PyQt and the old style slot/signal method. I'm wanting to "do things right" and this would apparently include new style slot/signals, but I can't get it to work. For example, a signal object does not have connect() method.
>
> import PySide.QtCore
> @PySide.QtCore.Slot()
> def someSlot():
> pass
> someSignal = PySide.QtCore.Signal()
> someSignal.connect(someSlot)
>
> results in:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: 'PySide.QtCore.Signal' object has no attribute 'connect'
>
> Which would appear to be at odds with http://www.pyside.org/docs/pyside/PySide/QtCore/Signal.html
>
> There is documentation for PyQt and signals/slots which I tried to follow, but I couldn't find the equivalent for PySide.
>
> I'm assuming that I'm missing something obvious, but I can't see it.
>
> Tim Doty
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
More information about the PySide
mailing list