PDA

View Full Version : QGraphicsView.AnchorViewCenter inconsistency ?



AchipA
29th May 2009, 14:18
I have a scene that I want to show an overview on (=zoom out), keeping my current center position.

view.setTransformationAnchor(QGraphicsView.AnchorV iewCenter)
zoom = QTransform()
zoom.scale(zoom_out_factor)
view.setTransformation(zoom)

Now, this almost works. If my coordinates are large, all is well. The trouble starts if the viewport would have to show sub-zero coordinates to satisfy the transform. Instead of extending, it just clips the scene at 0, which in turn results in the whole scene drifting off-center.

Example: if I'm looking at QRect(100,100,40,40), after the transform I'll be looking at QRect(90,90,60,60), which is OK. However, If I start at QRect(0,0,40,40), the result is QRect(0,0,60,60) and not the desired QRect(-10,-10,60,60).

Is there any elegant way around this ? I'm using setSceneRect() or inserting dummy elements at extreme cordinates to avoid this clipping, but I keep thinking there must be a better way :(

wysota
30th May 2009, 13:33
What is your scene's rectangle?

AchipA
1st June 2009, 11:08
What is your scene's rectangle?

For example QRect(0,0,2000,500)

I'd like to keep the center (whereever it is) when I zoom out. However, as it is now, on zooming out when the upper left corner reaches 0,0 the AnchorViewCenter breaks -> it keeps 0,0 at top left causing the whole view to slide. If I do a setSceneRect() with extreme values, or insert dummy QGraphicsItems on the corners of the zoomed out view, it works, but that's an ugly workaround :(

wysota
1st June 2009, 18:26
What happens if you call:

view->fitInView(view->sceneRect());?