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 <[email protected]>
To: Jason H <[email protected]>
Cc: "[email protected]" <[email protected]>
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:

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

Reply via email to