<HTML>
<HEAD>
<TITLE>Re: [PyQt] GraphicsItem, QObject Inheritance problem</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>All you need to connect signals and slots is a qobject. You can create <B>any</B> qobject for this task.<BR>
<BR>
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:<BR>
<BR>
class ImageButton(QtGui.QGraphicsPixmapItem):<BR>
def __init__(self, pixmap, parent=None, oneshot=True):<BR>
QtGui.QGraphicsPixmapItem.__init__( self, pixmap, parent )<BR>
self.emitter = QtCore.QObject()<BR>
self.emitter.setObjectName("ImageButtonEmitter")<BR>
self.oneshot = oneshot<BR>
self.callback = None<BR>
<BR>
def mousePressEvent(self, event):<BR>
self.moveBy(1,1)<BR>
self.emitter.emit( QtCore.SIGNAL("clicked()") )<BR>
if self.callback:<BR>
self.callback()<BR>
<BR>
def mouseReleaseEvent(self, event):<BR>
if not self.oneshot:<BR>
self.moveBy(-1,-1) <BR>
<BR>
To connect to this signal as follows:<BR>
<BR>
foo = ImageButton(...)<BR>
foo.emitter.connect( foo.emitter, QtCore.SIGNAL(“clicked()”), pythonfunc )<BR>
<BR>
I find this to be cleaner than wrapping a QObject around the graphics item, but in internet speak YMMV.<BR>
<BR>
Brian<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'> <BR>
</SPAN></FONT></BLOCKQUOTE>
</BODY>
</HTML>