PDA

View Full Version : QGraphicsItemGroup position issue



yagabey
2nd April 2015, 16:10
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)


qDebug()<<theItem->scenePos();
qDebug()<<theItem->pos();

Debug output:


QPointF(0,0)
QPointF(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.

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


Thanks in advance...

wysota
2nd April 2015, 16:35
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.

yagabey
2nd April 2015, 16:42
Hi, Wysota,

that is the grouping action slot:


QGraphicsItemGroup *group = d->scene->createItemGroup(d->scene->selectedItems());
group->setFlag(QGraphicsItem::ItemIsMovable);
group->setFlag(QGraphicsItem::ItemIsSelectable);
d->scene->addItem(group);


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

wysota
3rd April 2015, 08:45
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.