Results 1 to 2 of 2

Thread: QGraphicsItemGroup pos() & scenePos() returns (0,0) for (130, 150)

  1. #1
    Join Date
    Apr 2009
    Location
    California
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphicsItemGroup pos() & scenePos() returns (0,0) for (130, 150)

    Hi,

    I'm creating an "align to top" function for the QGraphicsItem based objects in my application. If there is a QGraphicsItemGroup in the selection I want the group to align with the other objects. If I have 2 or more regular items it works fine, but if one of the items is a group it doesn't.

    In the attached example when I create the group ( "2" & "1") it is positioned at (130, 150). The group reports the pos() and scenePos() as (0,0). If I then set the positions of all selected items to the same y value the group ends up at (130,160) instead of the (130, 10) which I was expecting.

    Qt Code:
    1. foreach(QGraphicsItem *item, selectedItems()) {
    2. item->setPos(item->x(), 10);
    3. }
    To copy to clipboard, switch view to plain text mode 

    I've read the QGraphicsItemGroup docs several times, and I've googled and searched this site and I don't think I've missed anything too obvious. Any help you could provide is much appreciated!

    Thanks,
    B
    scene-align.tar.gz

  2. #2
    Join Date
    Apr 2009
    Location
    California
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsItemGroup pos() & scenePos() returns (0,0) for (130, 150)

    In case anyone else has this problem I ended up going with plan B and wrote a function to translate the position:

    Qt Code:
    1. QPointF Scene::calcGroupPos(QGraphicsItem *group, QPointF newScenePos)
    2. {
    3. QPointF origin = group->sceneBoundingRect().topLeft() - group->scenePos();
    4. QPointF delta = newScenePos - origin;
    5. return delta;
    6. }
    To copy to clipboard, switch view to plain text mode 

    However if anyone knowns a better way I'd love to hear it as it still causes minor issues.

    Thanks,
    B

Similar Threads

  1. QGraphicsItemGroup childItems() returns only count()
    By kefir in forum Qt Programming
    Replies: 8
    Last Post: 20th July 2011, 13:03
  2. pos() and scenePos() problem
    By sjwang in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2010, 23:35
  3. ItemAt and ScenePos
    By jano_alex_es in forum Newbie
    Replies: 3
    Last Post: 26th October 2009, 14:48
  4. ScenePos changes when rotating an item
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 23rd October 2009, 08:52
  5. QGraphicsItem::scenePos() or pos()
    By Gopala Krishna in forum Newbie
    Replies: 3
    Last Post: 11th February 2007, 19:23

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