Please help with child object coordinates
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.
Re: Please help with child object coordinates
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.
Re: Please help with child object coordinates
Quote:
Originally Posted by
devdon
. . .so that the key signature can be moved as a single piece.
Take a look at QGraphicsItemGroup
Re: Please help with child object coordinates
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.