All you need to connect signals and slots is a qobject. You can create any
qobject for this task.
Here is a concrete example, actually using a QGraphicsItem. This makes an
Image button that emits a signal "clicked()" and move the graphics to mimic a
button press:
class ImageButton(QtGui.QGraphicsPixmapItem):
def __init__(self, pixmap, parent=None, oneshot=True):
QtGui.QGraphicsPixmapItem.__init__( self, pixmap, parent )
self.emitter = QtCore.QObject()
self.emitter.setObjectName("ImageButtonEmitter")
self.oneshot = oneshot
self.callback = None
def mousePressEvent(self, event):
self.moveBy(1,1)
self.emitter.emit( QtCore.SIGNAL("clicked()") )
if self.callback:
self.callback()
def mouseReleaseEvent(self, event):
if not self.oneshot:
self.moveBy(-1,-1)
To connect to this signal as follows:
foo = ImageButton(...)
foo.emitter.connect( foo.emitter, QtCore.SIGNAL("clicked()"), pythonfunc )
I find this to be cleaner than wrapping a QObject around the graphics item, but
in internet speak YMMV.
Brian
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt