QGraphicsview has a setDragMode(ScrollHandDrag) method to enable left-click panning. But I wanted to enable panning when I click the mouse wheel (middle button) and created the following custom implementation for panning:
//Within a custom derived class of QGraphicsView //pan is true when wheel is clicked and false when released //last Pos is defined somewhere else in the class void GridView::mouseMoveEvent(QMouseEvent *event){ if(pan){ QPointF currentPos = event->pos(); QPointF relPos = currentPos - lastPos; lastPos = currentPos; //this is what creates the panning effect translate(relPos.x(), relPos.y()); } QGraphicsView::mouseMoveEvent(event); }
This works fine for the most part. But, for example, if I scale the identity matrix to 1,000,000, this method will fail and stop panning (as if the view was stuck). This problem does not occur if I use setDragMode()
What would be the correct custom implementation of setDragMode() to turn it on with the click of a wheel?
source share