Layering problem of a QGraphicsItem with a GrandParent, Parents and children
-
I've got a QGraphicItem with a GrandParent, parents and children. The problem I'm trying to work around is that the layering is relative to the Grandparent's zValue and I need layering to be relative to the parents' zValue. Or have no relative layering, but instead have children be stacked based on their individual zValues. I have several of the items in a scene and would like to bring up all the parents on a certain a layer up to the forefront. One item can have parents on multiple layers. Any Suggestions?
-
Layering is relative to the item's parent. Of course, the parent's layering is relative to it's parent (which is the original item's grandparent).
You can choose whether children are in front of their parent (default), or whether they can also be behind the parent (QGraphicsItem::ItemStacksBehindParent and QGraphicsItem::ItemNegativeZStacksBehindParent). These are the possibilities. If you need anything else, you have to find an alternative to parenting, and live with all the consequences.
That said, I didn't really understand what your intention is. I hope my general answer helps you in some way.
-
Thank you for your reply. Sorry for the vagueness, hopefully this will clarify it a little better.
Let's say we have the following the grandPa items in the scene: grandPa_A and grandPa_B.
GrandPa_A has parentA and parentB.
GrandPa_B has parentC, parentD and parentE.
ParentA and parentD are on the same level but they have different parents(grandPa's).
I want to bring parentA and parentD to the forefront. I want parentA , parentD and their children to be stacked ontop of parentB, parentC, parentE and their children by using setZValue for the parents and children.
However since the stacking order is relative to the grandparent's zValue, I can only control stacking the grandparents and have no individual stacking control of the parents and their children.
The grandParent is needed because it is the grandparent that knows how the children and grandchildren need to move based on the position of the other children.
-
I'm afraid you won't be able to have both: Parenting the way describe, and z-order how you want it.
-
@Asperamanca Thank you again for your help. Cheers