PDA

View Full Version : Strange behavior of GraphicsView when change the scale of affine transform.



tonnot
26th September 2011, 12:22
I had this code for affine transform to draw on a QWidget.
AFT.reset();
AFT.translate(scrollh, scrollv); // pixelxs h from 0 to middle of widget , pixelxs v from 0 to middle of widget
AFT.scale(scalx, -scaly); // scale relation betwen my world bounds in cartersian coordinates and the width / heigth of the widget.
AFT.translate(-xc, -yc); // real coordinates of the center


Now I'm going to use Qgraphicsview / Qgraphicscene.
I have a widget extends Qgraphicsview with a Qgraphicscene. created into it.
I appy the transform to the view. (setTransform (AFT);

I draw my elements. OK, the initial view is centered and this 'world' entitities are drawed right.

If I increase or decrease the scalx scaly, the redraw shows me a world not centered, with an arbitratious center choosen.
Only when the scale is bigger (like a zoom - ) than neccesary the 'world' is centered.

(My code worked well when it was applied to a qwidget/paint )
Qgraphicsscene has not limits (that is to say I have not SceneRect)

Any idea ? It is as Qgraphicsscene was doing something -.....
Thanks

wysota
26th September 2011, 14:45
What is the effect you want to obtain?

tonnot
26th September 2011, 16:08
Always centered of course.
Here you are a video (avi file, can you see it ?)

wysota
26th September 2011, 20:29
What should be centered related to what?

tonnot
26th September 2011, 22:55
Solved with :

setTransformationAnchor(QGraphicsView::NoAnchor);
setSceneRect(rectf); // the limits of 'my world'

But I dont undertand why ...
I think that if you have an affine transform applied nothing more would be needed, but ...

There is 'hidden' actions inside this two options...
Thanks