Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middle Click to Pan #3

Open
samclane opened this issue Jul 31, 2018 · 0 comments
Open

Middle Click to Pan #3

samclane opened this issue Jul 31, 2018 · 0 comments

Comments

@samclane
Copy link
Owner

When working on the WorldFrame where I inherit from QGraphicsView to display a QGraphicsObject (WorldView). I have already implemented the image zoom functionality from this post, and I have tried using their implementation of pan, and have found that it works. However, I want to be able to do the pan without toggling, simply by holding down the middle mouse button and dragging from there.

I've written this code to switch between the two modes (normal and drag), and then call it on mouse(Press/Release)Events.

(in QGraphicsView)

def toggleDragMode(self):
    if self.dragMode() == QGraphicsView.ScrollHandDrag:
        self.setDragMode(QGraphicsView.NoDrag)
        self.pointerMode = PointerMode.Normal
    else:
        self.setDragMode(QGraphicsView.ScrollHandDrag)
        self.pointerMode = PointerMode.Drag

def mousePressEvent(self, event):
    if event.buttons() & Qt.MiddleButton:
        self.toggleDragMode()
    ...
    super().mousePressEvent(event)

def mouseReleaseEvent(self, event):
    if self.dragMode() == QGraphicsView.ScrollHandDrag:
        self.setDragMode(QGraphicsView.NoDrag)
        self.pointerMode = PointerMode.Normal
    super().mouseReleaseEvent(event)

(Sidenote: With the mouseReleaseEvent, I found that I couldn't use event.buttons() & Qt.MiddleButton to check if the middle button was released, so I always check and release in this case.)

However, whenever I try and middle-click and drag, no pan happens. However, I have confirmed this works correctly whenever I use the left mouse button as the binding (i.e. if event.buttons() & Qt.LeftButton: toggleDrag()). There has to be some code in QGraphicsView.mouseMoveEvent() that checks to see if the left button is held AND the cursor is in DragMode. Is there a way to change the keybinding on that deeper level?

EDIT: I just found this link and tried it by doing this (in QGraphicsView)

def __init__(*args, **kwargs):
  ...
  self.STOP_GLOBAL_SCROLLING = 1

But to no avail. Still, it's an interesting lead.


Here's the stackoverflow question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant