Results 1 to 2 of 2

Thread: QGraphicsRectItem

  1. #1
    Join Date
    Dec 2008
    Posts
    52
    Thanks
    3
    Qt products
    Qt4

    Default QGraphicsRectItem

    Hi
    I have a QGraphicsScene scene and Item which inherits the QGraphicsRectItem properties. I am taking points from scene MousePressEvent and MouseReleseevents and Drawing a Rectangle with
    Qt Code:
    1. QRect(TopLeft,BottomRight)
    To copy to clipboard, switch view to plain text mode 
    with both points(MousePressEvent and MouseReleseevents ).
    Whem I say
    Qt Code:
    1. item->rotate(qreal);
    To copy to clipboard, switch view to plain text mode 
    the item is been rotated from the topleft point where as i want it to rotate from center of the Rectangle.
    Hope u got my point. So, What i need to do to rotate item from its center point.

  2. #2
    Join Date
    Dec 2007
    Posts
    627
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsRectItem

    Quote Originally Posted by c_srikanth1984 View Post
    What i need to do to rotate item from its center point.
    By-default the rotation point it the origin of that item i.e. topleft corner.
    To translate around an arbitrary point (x, y), you need to combine translation and rotation with setTransform().
    Qt Code:
    1. Example:
    2.  
    3. // Rotate an item 45 degrees around (0, 0).
    4. item->rotate(45);
    5.  
    6. // Rotate an item 45 degrees around (x, y).
    7. item->setTransform(QTransform().translate(x, y).rotate(45).translate(-x, -y));
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to yogeshgokul for this useful post:

    c_srikanth1984 (30th July 2009)

Similar Threads

  1. QGraphicsWidget vs. QGraphicsRectItem
    By Bill in forum Newbie
    Replies: 3
    Last Post: 27th July 2009, 10:02
  2. Custom QGraphicsRectItem with size grip
    By Bill in forum Newbie
    Replies: 7
    Last Post: 23rd July 2009, 14:43
  3. QGraphicsRectItem and QGraphicsTextItem.
    By cydside in forum Qt Programming
    Replies: 13
    Last Post: 20th July 2009, 13:11
  4. QGraphicsRectItem selected line
    By Bill in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2009, 16:03
  5. Question about QGraphicsRectItem
    By lni in forum Qt Programming
    Replies: 10
    Last Post: 28th January 2009, 22:58

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.