Results 1 to 3 of 3

Thread: PyQt4 QGraphicsView and 'pressed' signal

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    2
    Qt products
    Platforms
    Unix/X11

    Default Re: PyQt4 QGraphicsView and 'pressed' signal

    Thanks for your reply. In my actual application i'm trying to use signals/slots to combine the functions dealing with remapping the QGraphicsView drag button from left to middle. The following is the relevant code i've lifted from my application:

    Qt Code:
    1. #TODO: Make signals work properly
    2. def mousePressEvent(self, event):
    3. self.emit(SIGNAL("pressed"), (event))
    4. QtGui.QGraphicsView.mousePressEvent(self, event)
    5. def mouseReleaseEvent(self, event):
    6. self.emit(SIGNAL("released"), (event))
    7. QtGui.QGraphicsView.mouseReleaseEvent(self, event)
    8. ######
    9.  
    10. #Assigned via self.connect(self, SIGNAL('pressed'), self.grabCanvas) in __init__
    11. def grabCanvas(self, event):
    12. if event.buttons() == QtCore.Qt.MidButton:
    13. origMode = self.dragMode()
    14. self.setDragMode(self.ScrollHandDrag)
    15. #Send a fake LMB press, TODO: Disable scene's selection of objects
    16. fake_event = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, event.pos(),
    17. QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.KeyboardModifiers())
    18. QtGui.QGraphicsView.mousePressEvent(self, fake_event)
    19.  
    20. #Add a handler to catch the mouse up event
    21. def revert(event):
    22. self.setDragMode(origMode)
    23. self.disconnect(self, SIGNAL("released"), revert)
    24.  
    25. self.connect(self, SIGNAL("released"), revert)
    To copy to clipboard, switch view to plain text mode 

    As you can perhaps see, i'm trying to make a temporary slot to reset some parameters when the button is released. I felt the most elegant and unobtrusive way of doing this would be using signals/slots rather than two event listeners and a bunch of shared flags (like middleButtonPressed, originalDragMode etc.).
    Last edited by splondike; 8th October 2009 at 13:36. Reason: Clarify how grabCanvas assigned

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.