Skip to content
  • 0 Votes
    10 Posts
    303 Views
    Pl45m4P

    @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).

    https://www.youtube.com/watch?v=wg9bI8-Qx2Q

    @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).

  • 0 Votes
    12 Posts
    602 Views
    Pl45m4P

    @StudentScripter said in QGraphicsRectItem item translation instead of movement?:

    Well the real problem seems to be that rect().setTopLeft() and all other direct changes to the parentitems rect result in a changed Origin Point of the object in the scene, while with setScale() the OriginPoint stays intact.

    AFAIK the "topLeft" of an item rotated by 90° clockwise is still the same point as when not being transformed... the original item stays the same, because you can revert the transformation at any time to get your initial item back. The QTranform only "maps" the initial item matrix to your transformed one.
    So I think calling setTopLeft manually will mess up your item and the current transformation completely.

  • 0 Votes
    5 Posts
    1k Views
    T

    At the end I've researched again the view's transformations and concluded to support both features and warn for the complexity.

    I did not re-implement the add/remove items of the scene together with a group. Thanks for the hint @Asperamanca .

  • 0 Votes
    2 Posts
    569 Views
    Christian EhrlicherC

    @michelmadeira said in How to rotate a Pixmap around bottom, right corner?:

    How to change anchor point of a pixmap rotation?

    By modifying your QTransform to set 0/0 to the bottom right corner because the Qt coordinate system starts with 0/0 in the upper left.

  • 0 Votes
    1 Posts
    650 Views
    No one has replied