Results 1 to 4 of 4

Thread: QGraphicsItemGroup boundRect problem with transformed children

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question QGraphicsItemGroup boundRect problem with transformed children

    Hi,

    I have a problem creating a group from a series of items if one of them has a transformation matrix.

    I add the items by:

    Qt Code:
    1. for (int pos2 = 0; pos2 <= tnkItems.count() -1;pos2++)
    2. {
    3. group->addToGroup(tnkItems[pos2]);
    4. }
    To copy to clipboard, switch view to plain text mode 

    If the items do not have any transformation group->boundingRect() return the total area of its children. But if any of its items has a transformation matrix , for example scale(2, 1 ), group->boundingRect() return an area bigger than its child items.

    Any idea why?

    Many thanks,
    Carlos.

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsItemGroup boundRect problem with transformed children

    See QGraphicsItem::boundingRect it clearly says:
    ...
    Although the item's shape can be arbitrary, the bounding rect is always rectangular, and it is unaffected by the items' transformation.
    ...
    So group->boundingRect() should return always the same value independently of own transformation.
    BUT if children transformation changes then group->boundingRect() can change (in case of one item MUST change) since area occupied by the child (in coordinates of group) is changed when transformation is applied on child.
    It is like changing area of painting.

  3. #3
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItemGroup boundRect problem with QGraphicsProxyWidget

    Hi MarekR22

    I traced the problem to this:

    The scene has QGraphicsPolygonItems that act as containers for QGraphicsProxyWidgets.

    The ProxyWidget fill the size of its container polygon. The proxy Ignores Transformations. If the container gets transformed for example scale(2,1), I change the size of the widget in the proxy to fill the container with this code:

    Qt Code:
    1. float w2;
    2. float h2;
    3. w2 = container->sceneBoundingRect().width();
    4. h2 = container->sceneBoundingRect().height();
    5. widgetOfProxy->setGeometry(0,0,w2,h2);
    To copy to clipboard, switch view to plain text mode 

    After this the size of the proxy is twise its original size to fill the area of the container.

    If I create a group using this object the resulting group is twice the observable size.

    You can access an example of this here:
    www.qlands.com/other_files/test.tar.gz


    Many thanks for your help
    Carlos.

  4. #4
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItemGroup boundRect problem with QGraphicsProxyWidget

    I'm replying to my own post.

    This happens because the bounding rectangle of the group is calculated by summing the bounding rectangle of all its children using childrenBoundingRect() and mapping the result rectangle to the group. Because the childrenBoundingRect reach the widget and the the widget size can change, this results in a erroneous bounding rectangle for the group.

    I fixed this by overriding the boundingRect() and paint functions.

    I hope this would help others with the same problem.

    Closed thread.

    Carlos.

Similar Threads

  1. QtEmbedded 4.70 QGraphicsItemGroup Problem
    By QbelcorT in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 27th November 2010, 08:26
  2. QGraphicsItemGroup bounding rect problem
    By jonks in forum Qt Programming
    Replies: 2
    Last Post: 28th October 2010, 04:02
  3. Replies: 11
    Last Post: 27th October 2010, 19:48
  4. problem in QGraphicsItemGroup
    By wagmare in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2009, 08:27
  5. QGraphicsItemGroup problem
    By init2null in forum Qt Programming
    Replies: 2
    Last Post: 20th November 2006, 22:45

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.