Hello!
With the QGraphicsView framework I want to implement a scroll fade out feature. That means that I drag the scene with the mouse just like in the ScrollHandDrag mode, but when I release the button it shouldn't stop abruptly, but keep scrolling and slow down to come to a stop. I would love to build upon the existing ScrollHandDrag mode, because it does its job really well. It scrolls smoothly and stops at the scene border. I have no idea how to trigger it programmatically though.
Question one: Is there a way I can reuse the ScrollHandDrag mode programmatically?
Alright, so I thought I'll just override the mouse events and e.g. use translate() in the mouseMoveEvent like so.
void GraphicsViewWidget
::mouseMoveEvent(QMouseEvent *event
) {
QPoint mouseDiff
= mouse
- lastMouse;
lastMouse = mouse;
translate(mouseDiff.x(), mouseDiff.y());
update();
}
void GraphicsViewWidget::mouseMoveEvent(QMouseEvent *event)
{
QPoint mouse = event->pos();
QPoint mouseDiff = mouse - lastMouse;
lastMouse = mouse;
translate(mouseDiff.x(), mouseDiff.y());
update();
}
To copy to clipboard, switch view to plain text mode
Nope, it doesn't do much. The scene barely moves by a pixel. Even if I use it with hard coded values, say translate(100,100) the scene does not move. Apparently, setting any QTransform with setTransform() seems to have no effect.
Question two: Why doesn't any custom view transformation seems to work for me?
When I replace translate() with scroll(), then the scene does move, but it's very jittery. And also it doesn't stop at the scene border.
To avoid the jitter, I could remember the transform when the mouse was clicked and then calculate a new transform that is translated by the entire length of what the mouse has moved since the click was placed. But I don't see anything like a "scrollTo()" interface to go with that approach.
Question three: How do I do it right? 
I don't want the scroll bars at all btw. I just keep them hidden and hope that they don't interfere.
Bookmarks