1 Attachment(s)
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.
Code:
item->setPos(item->x(), 10);
}
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
Attachment 6907
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:
Code:
{
QPointF origin
= group
->sceneBoundingRect
().
topLeft() - group
->scenePos
();
QPointF delta
= newScenePos
- origin;
return delta;
}
However if anyone knowns a better way I'd love to hear it as it still causes minor issues.
Thanks,
B