document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #
  2. # Example 1 - Call the class directly with the instance as an arg
  3. #
  4. class RigModuleUi(QtGui.QMainWindow,Ui_RiggingModuleUI):
  5.     def __init__(self,parent = None):
  6.         super(RigModuleUi,self).__init__(parent = parent)
  7.         self.setupUi(self)
  8.  
  9.         self.GraphicsView.mousePressEvent = self.qView_mousePressEvent
  10.  
  11.     def qView_mousePressEvent(self,event):
  12.         if event.button() == QtCore.Qt.LeftButton:
  13.             view = self.GraphicsView
  14.             QtGui.QGraphicsView.mousePressEvent(view, event)
  15.  
  16.  
  17. #
  18. # Example 2 - Save the original bound method to call later
  19. #
  20. class RigModuleUi(QtGui.QMainWindow,Ui_RiggingModuleUI):
  21.     def __init__(self,parent = None):
  22.         super(RigModuleUi,self).__init__(parent = parent)
  23.         self.setupUi(self)
  24.  
  25.         view = self.GraphicsView
  26.         view._mousePressEvent = view.mousePressEvent
  27.         view.mousePressEvent = self.qView_mousePressEvent
  28.  
  29.     def qView_mousePressEvent(self,event):
  30.         if event.button() == QtCore.Qt.LeftButton:
  31.             view = self.GraphicsView
  32.             view._mousePressEvent(event)
  33.  
  34.  
  35. #
  36. # Example 3 - Use an event filter to manage multuple composed objects
  37. #
  38. class RigModuleUi(QtGui.QMainWindow,Ui_RiggingModuleUI):
  39.     def __init__(self,parent = None):
  40.         super(RigModuleUi,self).__init__(parent = parent)
  41.         self.setupUi(self)
  42.  
  43.         self.GraphicsView.mousePressEvent = self.qView_mousePressEvent
  44.  
  45.     def eventFilter(self, obj, event):
  46.         if obj is self.GraphicsView:
  47.             # If its not a left button then we wanted to do
  48.             # some custom handling, so we call our own handler
  49.             # and return True which means that the event is filtered
  50.             # and the original object will not ever see this event.
  51.             if event.button() != QtCore.Qt.LeftButton:
  52.                 self.qView_mousePressEvent(event)
  53.                 return True
  54.  
  55.         return super(RigModuleUi, self).eventFilter(obj, event)
  56.  
  57.     def qView_mousePressEvent(self, event):
  58.         event.accept()
  59.         view = self.GraphicsView
  60.         # do something custom with the view and event
');