I first started out by doing the same thing, and replacing the bound method 
with another one. Nowadays I find it a bit messy and prefer the event filter 
approach if I am not subclassing the target object.

Here are two example of the way you are trying to do it, followed by the event 
filter approach...
(http://pastebin.com/EUAEJ0TH)

###
## Example 1 - just call the class directly
class RigModuleUi(QtGui.QMainWindow,Ui_RiggingModuleUI):
    def __init__(self,parent = None):
        super(RigModuleUi,self).__init__(parent = parent)
        self.setupUi(self)

        self.GraphicsView.mousePressEvent = self.qView_mousePressEvent

    def qView_mousePressEvent(self,event):
        if event.button() == QtCore.Qt.LeftButton:
            view = self.GraphicsView
            # directly call the class and pass the instance
            QtGui.QGraphicsView.mousePressEvent(view, event)

## Example 2 - save the original bound method
    def __init__(self,parent = None):
        ...
        view = self.GraphicsView
        view._mousePressEvent = view.mousePressEvent
        view.mousePressEvent = self.qView_mousePressEvent

    def qView_mousePressEvent(self,event):
        if event.button() == QtCore.Qt.LeftButton:
            view = self.GraphicsView
            view._mousePressEvent(event)

## Example 3 - Use an event filter to manage composed objects and route their 
actions
class RigModuleUi(QtGui.QMainWindow,Ui_RiggingModuleUI):
    def __init__(self,parent = None):
        super(RigModuleUi,self).__init__(parent = parent)
        self.setupUi(self)

        self.GraphicsView.mousePressEvent = self.qView_mousePressEvent

    def eventFilter(self, obj, event):
        if obj is self.GraphicsView:
            # If its not a left button then we wanted to do
            # some custom handling, so we call our own handler
            # and return True which means that the event is filtered
            # and the original object will not ever see this event.
            if event.button() != QtCore.Qt.LeftButton:
                self.qView_mousePressEvent(event)
                return True

        return super(RigModuleUi, self).eventFilter(obj, event)

    def qView_mousePressEvent(self, event):
        event.accept()
        view = self.GraphicsView
        # do something custom with the view and event

####
I like the event filter approach because I don't have to replace the bound 
methods at all. I simply catch the events before the objects ever see them. You 
can route multiple objects in that event filter and send them to other methods.

-- justin




On Mar 1, 2013, at 6:18 AM, illunara wrote:

> Hi everybody
> 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.
> 
> I try this too, but no go at all.
> 
> super(QtGui.QGraphicsView,self.GraphicsView).mouseMoveEvent(event)
> 
> Thanks
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to