@StudentScripter
The Transformation Example:
(I modified the default number of 3 sequencial transformations to 5)
Rotation.png
As you see, with every rotation the coordinate system (the orientation) of each point of your object (here: the house) changes...
So also the anchor points have an orientation and a coordinate system... when you change the anchor from, say, bottom-left to top-right, the rotation angle and offset to represent the same pose of the house/your rect also changes.
You have to break down everything into single operations as soon as you change your anchor and then apply them one after another.
In the example the anchor is the center of the item.
[0]-[1]: just shifts/translates by +50 along both axis
[1]-[2]: rotates house by 60°CW around center
[2]-[3]: same here
[3]-[4]: same here
[4]-[5]: and here
If you would have changed the anchor (add offset, rotate/apply rot mat, take offset) as you do, you have to sum up ( i.e. multiply matrices) all these operations in the "chain".
And in between when moving from one anchor to the next, you have to add the translation for the point itself.
Edit:
While it is possible to save() and restore() a transformed QPainter (the example above paints the objects directly), the API of QGraphicsItem only allows to set one transformation (setTransform) at a time to scale, shift, rotate the whole thing....
and this transformation is relative to exactly one origin.
So starting from the initial origin (0/0) by design, you shift to your inital origin (i.e. bottom-left corner = the anchor point you want to start with).
To use to chain of multiple and different transformations you need to shift from your current anchor back to the (0/0) point every time (as you do) and pay respect to any possible rotation/translation relative to former anchor points.
But then from your latest anchor's POV.
This is why you can't get around solving the "puzzle".
Search for rotations in R2, R3 (2D, 3D) space with a not fixed(!) object coordinate system (since you move your origin)...
the "world" coordinate system in where we operate (here the scene coords) stays the same and we rotate along the same axis. However we move the usually fixed object orientation when changing the "anchor".
Maybe it helps to move this issue to 3D space (it adds one dimension to the vectors and matrices, but I mean for your understanding).
@Pl45m4 said in QTransform graphicsitems shifting when origin changed:
For this I think you have to take the offset (distance between those points) and their location (below/above, left/right from center/middle) into consideration... A shift of the origin, a change of the orientation of the axes.
What I meant here is what is explained in the video... using the "right-hand-rule"...
When moving the anchor (origin of the object's coordinate system) "just like that", the orientation might change as well (and not only the shift/translation is happening).