Results 1 to 4 of 4

Thread: How to rotate items in a QGraphicsScene while keeping them upright

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to rotate items in a QGraphicsScene while keeping them upright

    If I understand you right, you simply want to rotate the line mid point:
    Qt Code:
    1. QLine line = ...;
    2. QTransform t;
    3. t.rotate(angle); // actually just figure it out yourself how to rotate around specified point
    4. const QPoint mid = (line.p1()+line.p2)/2;
    5. const QPoint rotated_mid = t.map(mid);
    6. line.translate( rotated_mid-mid );
    To copy to clipboard, switch view to plain text mode 
    You cannot rotate the start and end points separately, it will change the line direction (if angle != 0).

  2. The following user says thank you to stampede for this useful post:

    wayfaerer (5th February 2012)

  3. #2
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default Re: How to rotate items in a QGraphicsScene while keeping them upright

    Thank you! That worked, although I actually wound up finding a simpler solution for my specific case. The lines are on top of QGraphicsItems that *do* rotate normally. So all I had to do was set each line's parent as its corresponding QGraphicsItem, then set the ItemIgnoresTransformations flag on the lines. I think I'm going to wind up using your approach elsewhere, though. Thanks again.

Similar Threads

  1. QGraphicsScene is SLOW with a lot of items !
    By pl01 in forum Qt Programming
    Replies: 11
    Last Post: 5th August 2011, 16:06
  2. How to add items in a QGraphicsScene?
    By schmimona in forum Qt Programming
    Replies: 2
    Last Post: 3rd August 2011, 08:53
  3. Rotate Item qgraphicsscene
    By pispipepe in forum Qt Programming
    Replies: 5
    Last Post: 28th July 2010, 20:05
  4. Animating many items in a QGraphicsScene
    By Luc4 in forum Qt Programming
    Replies: 6
    Last Post: 5th May 2010, 06:55
  5. How could I save Items on a QGraphicsScene?
    By pinkfrog in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2009, 05:03

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.