PDA

View Full Version : Please help with child object coordinates



devdon
5th October 2011, 11:00
I'm placing the symbols in a musical key signature on a musical staff. This part is successful. All the symbols are successfully placed individually using scene->addItem(mySigItem); mySigItem->setPos(tx,ty);

But I'd like the first symbol to be the parent item and the rest of the symbols be child items so that the key signature can be moved as a single piece. When I change the lines to mySigItem2->setParentItem(mySigItem1) then the position of the second item is FAR to the right and down the screen. I have tried setting the flag ItemIgnoresTransformations, mapTo/FromScene, mapFrom/ToParent, etc. and everything else I can think of or find in the docs. The coordinates work individually placed but simply setting the item as a child breaks them and they wander off.

Please help me figure out what I'm doing wrong. Thanks.

wysota
5th October 2011, 16:45
Item position is always determined relative to its parent (or the scene if the item has no parent). Thus you need to set position of notes relative to the key item. If you only know the absolute scene position then you can always use keyItem->mapFromScene() to determine the position relative to the key item.

norobro
5th October 2011, 16:48
. . .so that the key signature can be moved as a single piece.
Take a look at QGraphicsItemGroup

devdon
5th October 2011, 20:58
thanks for your response.

QGraphicsItemGroup is just what I was looking for but had overlooked in the docs. Thanks!

This relative behavior is counter-intuitive to my newbie brain. I think in scene coordinates. But I see now how I can work it out. Thank you very much for your response.