<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
<kelley@eyesopen.com><br><b><span style="font-weight: bold;">To:</span></b> Jason H <scorp1us@yahoo.com><br><b><span style="font-weight: bold;">Cc:</span></b> "pyqt@riverbankcomputing.com" <pyqt@riverbankcomputing.com><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. 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>
</div></div></div><br>
</body></html>