0

I'm using QtDesign to create my own UI and convert it to python version. So after subclass the UI python file, i had written some function to implement mouseEvent for QGraphicsView. Just one small question. How can i call the super() function for the QGraphicsView?

class RigModuleUi(QtGui.QMainWindow,Ui_RiggingModuleUI):
    def __init__(self,parent = None):
        super(RigModuleUi,self).__init__(parent = parent)
    self.GraphicsView.mousePressEvent = self.qView_mousePressEvent

    def qView_mousePressEvent(self,event):
        if event.button() == QtCore.Qt.LeftButton:
            super(RigModuleUi,self).mousePressEvent(event)

Look like the super(RigModuleUi,self).mousePressEvent(event)will return the mouseEvent for QMainWindow, not QGraphicsView. So all other option for mouse like rubberBand will lost.

Thanks

illunara
  • 327
  • 1
  • 5
  • 15
  • Your question is not clear. What is `self.GraphicsView`? A `QGraphicsView` instance? Because by your comment to Eevee's answer it's *definitely* not an instance of `QGraphicsView`. – Bakuriu Feb 28 '13 at 14:18

1 Answers1

0

I'm not quite sure what you expect to happen here. You're storing a bound method. When it's called, it'll still be called with the same self it had when you stored it.

Your super is walking up the ancestry of RigModuleUi, which doesn't inherit from QGraphicsView.

self.GraphicsView is a funny name for an instance attribute; is that supposed to be the name of a class, or is it just capitalized incidentally? (Please follow PEP8 naming conventions.) Perhaps you'd have more luck if you defined the method as a global function and assigned that to the instance.

def qView_mousePressEvent(self, event):
    if event.button() == QtCore.Qt.LeftButton:
        super(QGraphicsView, self).mousePressEvent(event)

class RigModuleUi(QtGui.QMainWindow, Ui_RiggingModuleUI):
    def __init__(self, parent=None):
        super(RigModuleUi,self).__init__(parent=parent)
        self.GraphicsView.mousePressEvent = qView_mousePressEvent

Guessing wildly here; I don't know PyQt's class hierarchy :)

Eevee
  • 47,412
  • 11
  • 95
  • 127
  • TypeError: super(type, obj): obj must be an instance or subtype of type This is what i had try `super(QtGui.QGraphicsView, self.GraphicsView).mousePressEvent(event)` But still, its not working.... Btw, self.GraphicsView is name of QGraphicsView object i had created in QtDesign, and thank for the link you gave me :D – illunara Feb 28 '13 at 09:30
  • are you using `reload()`, or other funny module-loading tricks? those can screw up `super()`. – Eevee Feb 28 '13 at 20:26