Results 1 to 4 of 4

Thread: QGraphicsItemGroup position issue

  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default QGraphicsItemGroup position issue

    Hi,

    I create a QGraphicsItemGroup from existing graphicsItems on the scene.
    Strange thing: When i debug the initial position of QGraphicsItemGroup , I always see (0,0)

    Qt Code:
    1. qDebug()<<theItem->scenePos();
    2. qDebug()<<theItem->pos();
    To copy to clipboard, switch view to plain text mode 

    Debug output:

    Qt Code:
    1. QPointF(0,0)
    2. QPointF(0,0)
    To copy to clipboard, switch view to plain text mode 

    When i move the group on the scene the position info is always shifted according to the initial position. For example ; if i create two different item groups on different parts of the scene, group->scenePos() infos are not the same although i get them on top of each other.

    Is that an expected behavior, or am i missing something?


    Thanks in advance...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItemGroup position issue

    Quote Originally Posted by yagabey View Post
    I create a QGraphicsItemGroup from existing graphicsItems on the scene.
    Strange thing: When i debug the initial position of QGraphicsItemGroup , I always see (0,0)
    The initial position of any item is (0,0).

    When i move the group on the scene the position info is always shifted according to the initial position. For example ; if i create two different item groups on different parts of the scene, group->scenePos() infos are not the same although i get them on top of each other.
    I don't understand what you mean. Please provide an example reproducing the situation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QGraphicsItemGroup position issue

    Hi, Wysota,

    that is the grouping action slot:

    Qt Code:
    1. QGraphicsItemGroup *group = d->scene->createItemGroup(d->scene->selectedItems());
    2. group->setFlag(QGraphicsItem::ItemIsMovable);
    3. group->setFlag(QGraphicsItem::ItemIsSelectable);
    4. d->scene->addItem(group);
    To copy to clipboard, switch view to plain text mode 


    After creating the group, i expect the "group's position" to be the "topleft item's position" , but it is (0,0)

    Edit: Let me clarify ... Actually the item is not on (0,0) but "qDebug()<< group->pos() " prints " (0,0) " . The real position and pos() or scenepos() output does not match
    Last edited by yagabey; 2nd April 2015 at 15:50.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItemGroup position issue

    The item is at 0,0. Its bounding rect likely depends on the position of items it groups. If you move the group its position will change and it's rect will remain what it was. If you have two groups then they will have different rects. Moving them into the same position will not make items they contain have the same scene position.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. view position of mouse position in GraphicsScene
    By Raghaw in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2012, 04:46
  2. Events with QGraphicsItemGroup
    By onurozcelik in forum Qt Programming
    Replies: 2
    Last Post: 21st June 2011, 06:51
  3. Replies: 0
    Last Post: 16th July 2009, 12:44
  4. Add two QGraphicsItemGroup
    By ashishsaryar in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2008, 18:00
  5. setZValue of QGraphicsItemGroup
    By forrestfsu in forum Qt Programming
    Replies: 3
    Last Post: 6th November 2006, 19:40

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.