Results 1 to 10 of 10

Thread: Set the rotation of a QTransform

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Set the rotation of a QTransform

    Quote Originally Posted by quimnuss View Post
    And that's exactly what I was asking for, the final rotation value.
    Yes, you did.
    And I pointed out that you can accumulate that value by tracking which rotation values you apply.

    Cheers,
    _

  2. #2
    Join Date
    Oct 2014
    Posts
    81
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    20
    Thanked 9 Times in 9 Posts
    Wiki edits
    7

    Default Re: Set the rotation of a QTransform

    Keeping the transformation values in your own variables and rebuilding the QTransform when you need it is the simplest way (I would go with that as well).

    But if you really need to modify the rotation from the QTransform, the first two values of the first and second rows ( [m11,m12] and [m21,m22]) describe two 2D vectors that are rotated around an origin. One vector represents the horizontal axis and the other the vertical axis of this transformed space.
    They're usually perpendicular. When there's shearing involved they're not perpendicular, this is what causes shearing after all.

    The length of these vectors is the scale.
    Translation is not involved in this, it's the third row.

    So if you want to change the rotation while preserving the scale, first obtain the length of each vector (Pythagorean theorem) , rotate the vectors by the desired amount and scale them by the original length.

    vecHx = Cos( angle ) * originalScaleH
    vecHy = Sin( angle ) * originalScaleH

    vecVx = Cos( angle - 90 ) * originalScaleV
    vecVy = Sin( angle - 90 ) * originalScaleV

    [vecHx,vecHy] = [m11,m12]
    [vecVx,vecVy] = [m21,m22]

    If I'm not mistaken it's as simple as that. The "-90" might be wrong depending on the orientation expected by Qt (in which case "+90" would be the right choice, or something else).
    Last edited by Kryzon; 8th July 2015 at 02:52.

  3. #3
    Join Date
    Jul 2015
    Posts
    52
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: Set the rotation of a QTransform

    Thanks Kryzon,

    Since apparently the object's QTransform doesn't provide it, I'll go for the simple way and store the rotation and scale on my own. I'd play with the transformation affine matrix components if it became cumbersome to track the rotation.

Similar Threads

  1. QTransform rotation and scale issue
    By Talei in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2014, 17:53
  2. Replies: 0
    Last Post: 29th September 2011, 00:18
  3. QTransform()
    By mkind in forum Newbie
    Replies: 0
    Last Post: 19th February 2010, 22:45
  4. GraphicsItemChange and QTransform
    By ct-xuyaojun in forum Qt Programming
    Replies: 0
    Last Post: 28th September 2009, 10:16
  5. QTransform + drawLine ?
    By verburg in forum Qt Programming
    Replies: 0
    Last Post: 23rd January 2009, 01:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.