tags:

views:

836

answers:

3
A: 

I haven't done this myself but this is from the QGraphicsView documentation

... When the scene is larger than the scroll bars' values, you can choose to use translate() to navigate the scene instead.

By using scroll you are moving the widget, translate should achieve what you are looking for, moving the contents of the QGraphicsScene underneath the view

Harald Scheirich
Well, the scene isn't larger than the allowed values of the scrollbars, so it shouldn't be a problem. But I tried translating too, but that just sort of made the image shudder back and forth. I think it got re-centered automatically?
carlpett
I am looking at the docs, have you tried `setDragMode(QGraphicsView::ScrollHandDrag)` and is the value of `interactive` set to `true` ?
Harald Scheirich
re translate, you need view.setTransformationAnchor( QtGui.QGraphicsView.NoAnchor ) else translate() is a noop ?!
Denis
Denis: Thanks, that solved it!
carlpett
Harald: Thanks for your suggestiong, I just tried that. It changed how the widget moved around, but it was still the widget that got moved.
carlpett
A: 

You can set the QGraphicsScene's area that will be displayed by the QGraphicsView with the method QGraphicsView::setSceneRect(). So when you press the button and move the mouse, you can change the center of the displayed part of the scene and achieve your goal.

alisami
A: 

My addition to translate() method. It works great unless you scale the scene. If you do this, you'll notice, that the image is not in sync with your mouse movements. That's when mapToScene() comes to help. You should map your points from mouse events to scene coordinates. Then the mapped difference goes to translate(), viola - your scene follows your mouse with a great precision.

For example:

QPointF tmp2 = mapToScene(event->pos());
QPointF tmp = tmp2-mapToScene(previous_point);
translate(tmp.x(),tmp.y());
PF4Public