<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div>I think you and I are very close to a nice work-around. I see you're providing a object as a property, and connecting to that. <br>What I think should be possible, is to provide a QObject derived class (on the outside), then using __getattr__(self, name), __setattr__(self, name, value), and maybe __call__(self, args) and be able to transparently proxy them to the non-QObject object on the inside. <br><br>It isn't true inheritance, but it would get the job done. Is there anything like this already?<br><br><br><br></div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Brian Kelley
 &lt;kelley@eyesopen.com&gt;<br><b><span style="font-weight: bold;">To:</span></b> Jason H &lt;scorp1us@yahoo.com&gt;<br><b><span style="font-weight: bold;">Cc:</span></b> "pyqt@riverbankcomputing.com" &lt;pyqt@riverbankcomputing.com&gt;<br><b><span style="font-weight: bold;">Sent:</span></b> Thursday, October 1, 2009 10:34:59 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [PyQt] GraphicsItem, QObject Inheritance problem<br></font><br>


<title>Re: [PyQt] GraphicsItem, QObject Inheritance problem</title>

<font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 11pt;">All you need to connect signals and slots is a qobject. &nbsp;You can create <b>any</b> qobject for this task.<br>
<br>
Here is a concrete example, actually using a QGraphicsItem. &nbsp;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>
&nbsp;&nbsp;&nbsp;&nbsp;def __init__(self, pixmap, parent=None, oneshot=True):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QtGui.QGraphicsPixmapItem.__init__( self, pixmap, parent )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.emitter = QtCore.QObject()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self..emitter.setObjectName("ImageButtonEmitter")<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.oneshot = oneshot<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.callback = None<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;def mousePressEvent(self, event):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.moveBy(1,1)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.emitter.emit( QtCore.SIGNAL("clicked()") )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self.callback:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.callback()<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;def mouseReleaseEvent(self, event):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if not self.oneshot:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>
</div></div></div><br>

      </body></html>