PDA

View Full Version : Do not move QGraphicsItem after scaling



nilot
27th September 2016, 13:49
Hello,
In my QGraphicsScene I have a QGraphicsItem ( the red rectangle) and a QGraphicsLineItem. I can also change the scale of the view but my QGraphicsLineItem ignores the scale changes : to achieve that I used the following line of code:


myQGraphicsLineItem->setScale(1.0/scaleOfView);

So the two items don't have the same scale.
Unfortunately when the scale of the view changes, the relative position of my two items changes ( see the two captures) even if the scene positions of the two items remain the same . Do you understand why ?

1212612127


Thank you

anda_skoa
27th September 2016, 15:30
Very likely an issue with the transformation anchor.

When you scale manually you are probably scaling from the center of the item, not from the top left.

Cheers,
_

nilot
28th September 2016, 09:19
Hello,
I added this line


myQGraphicsLineItem->setTransformOriginPoint(topLeftPointOfTheLine);

and it works well, thank you.