[PyQt] GraphicsItem, QObject Inheritance problem
scorp1us at yahoo.com
Thu Oct 1 19:10:20 BST 2009
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.
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.
It isn't true inheritance, but it would get the job done. Is there anything like this already?
From: Brian Kelley <kelley at eyesopen.com>
To: Jason H <scorp1us at yahoo.com>
Cc: "pyqt at riverbankcomputing.com" <pyqt at riverbankcomputing.com>
Sent: Thursday, October 1, 2009 10:34:59 AM
Subject: Re: [PyQt] GraphicsItem, QObject Inheritance problem
Re: [PyQt] GraphicsItem, QObject Inheritance problem 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:
def __init__(self, pixmap, parent=None, oneshot=True):
QtGui.QGraphicsPixmapItem.__init__( self, pixmap, parent )
self.emitter = QtCore.QObject()
self.oneshot = oneshot
self.callback = None
def mousePressEvent(self, event):
self.emitter.emit( QtCore.SIGNAL("clicked()") )
def mouseReleaseEvent(self, event):
if not self.oneshot:
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt