Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Example 1 - Call the class directly with the instance as an arg
- #
- 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
- QtGui.QGraphicsView.mousePressEvent(view, event)
- #
- # Example 2 - Save the original bound method to call later
- #
- class RigModuleUi(QtGui.QMainWindow,Ui_RiggingModuleUI):
- def __init__(self,parent = None):
- super(RigModuleUi,self).__init__(parent = parent)
- self.setupUi(self)
- 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 multuple composed objects
- #
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement