Results 1 to 2 of 2

Thread: Resizing a rotated QGraphicsRectItem

  1. #1
    Join Date
    Jul 2012
    Thanked 1 Time in 1 Post
    Qt products
    Unix/X11 Windows

    Default Resizing a rotated QGraphicsRectItem

    I have a QGraphicsRectItem in my scene with a resize item like this post
    I can rotate and resize the item with mouse dragging.
    The problem I met is when I try to resize the rectangle after rotation, the drag direction is in scene coordinate but the resize direction is in the item coordinate.
    For example, if I drag the bottom edge in the blue arrow direction, the edge actually moves in the white arrow direction.
    Could anyone tell me how to make them consistant? (Dragging to white arrow direction and resizing to white arrow direction.)

    This is my resizing code in mouseMoveEvent(), the center of item is (0,0) in the item coordinate:
    Qt Code:
    1. QPointF pos = event->scenePos()-scenePos();
    3. if(m_selectedItem == 1) // left
    4. rect.setLeft(rectItem, pos.x()/rectItem->scale());
    5. else if(m_selectedItem == 3) // bottom
    6. rect.setBottom(pos.y()/rectItem->scale());
    7. else if(m_selectedItem == 5) // right
    8. rect.setRight(pos.x()/rectItem->scale());
    9. else if(m_selectedItem == 7) // top
    10. rect.setTop(pos.y()/rectItem->scale());
    12. // move the rectangle back to center
    13. QPointF point =;
    14. rect.moveCenter(QPointF(0, 0));
    15. rectItem->setRect(rect);
    16. rectItem->setPos(rectItem->mapToScene(point));
    To copy to clipboard, switch view to plain text mode 

    I tried the function mapToItem() but it seems not work, neither.
    Please ignore the extra attachment. I don't know how to remove it.
    Attached Images Attached Images
    Last edited by Seishin; 14th November 2012 at 20:06.

  2. #2
    Join Date
    Jul 2012
    Thanked 1 Time in 1 Post
    Qt products
    Unix/X11 Windows

    Default Re: Resizing a rotated QGraphicsRectItem

    Any Idea on how to map scene or viewport coord to the item coord?

Similar Threads

  1. Replies: 2
    Last Post: 15th March 2010, 11:03
  2. QGraphicsTextItem sharpness when rotated
    By martinn in forum Qt Programming
    Replies: 3
    Last Post: 26th February 2010, 13:13
  3. drawing series of rotated ellipses
    By qtn00b in forum Newbie
    Replies: 1
    Last Post: 17th December 2009, 02:51
  4. How draw a rotated text in a QPainterPath?
    By iw2nhl in forum Qt Programming
    Replies: 6
    Last Post: 17th August 2007, 19:55
  5. rotated labels
    By jayw710 in forum Qt Programming
    Replies: 2
    Last Post: 11th April 2006, 18:47

Tags for this Thread


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.