Results 1 to 8 of 8

Thread: MapToItem, MapToScene

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,349
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: MapToItem, MapToScene

    You don't need any of these to put child items inside a parent item.

    Each item, no matter what it is, has its own coordinate system. Its coordinate system is used to draw its own contents. Each item is sized and positioned according to the coordinate system of its parent item (or the scene if it is a top-level item).

    So if you have a QGraphicsRectItem with the size (100, 100), then its coordinate system goes from (0,0) to (99, 99). The top left corner is (0,0) and the bottom right corner is (99, 99). If you want to add a QGraphicsEllipseItem as a child, you make the child whatever size you want it to be (in the coordinate system of the parent rectangle), and place it inside the rectangle relative to the top left corner of the rectangle. The (0,0) coordinate for the ellipse is the top left corner of its boundingRect() (the rectangle that encloses the ellipse, not the rectangle you are using for its parent).

    If you want to place an ellipse exactly in the center of the parent QGraphicsRectObject, you have to offset the ellipse's position by the half of the width and half of the height of its boundingRect().

    Edit: Actually, I am not sure if the origin (0,0) of a QGraphicsItem is at the top left or at the center. Someone with a better memory might like to correct me if needed.
    Last edited by d_stranz; 29th January 2015 at 01:58.

Similar Threads

  1. Replies: 1
    Last Post: 13th November 2014, 08:15
  2. Using QGraphicsItem::mapToScene
    By Casper14 in forum Qt Programming
    Replies: 2
    Last Post: 22nd July 2014, 21:40
  3. Replies: 0
    Last Post: 14th June 2011, 16:02
  4. mapToItem() question
    By Alex Brophy in forum Newbie
    Replies: 2
    Last Post: 18th April 2008, 09:55

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.