c++ - Forcing QGraphicsItem to use z value and ignore the parent child relationship -
i have problem using qgraphicsitem
class.
there base_parent, base_part, part_1, part_2. base_parent parent of base_part. part_1 , part_2 children of base_part. want set z value of items in way part_1 , part_2 stack behind base_parent , base_part stacks in front of base_parent. i've implemented this:
base_part->setparentitem(base_parent); part_1->setparentitem(base_part); part_2->setparentitem(base_part);
at first tried setting z value using setzvalue() didn't work.
base_parent->setzvalue(0); base_part->setzvalue(1); part_1->setzvalue(-1); part_2->setzvalue(-2);
in documentation said that:
an item's children stacked on top of parent
i giving saw parameter.
you can call setzvalue() on item explicitly stack on top of, or under, other sibling items. default z value item 0. items same z value stacked insertion order.
you can call stackbefore() reorder list of children. directly modify insertion order.
you can set itemstacksbehindparent flag stack child item behind parent.
so tried setting itemstacksbehindparent
flag moved stacked whole child behind, meaning base_part, part_1 , part_2 stacked behind base_parent.
afterwards found flag, itemnegativezstacksbehindparent
.
the item automatically stacks behind it's parent if it's z-value negative. flag enables setzvalue() toggle itemstacksbehindparent. flag introduced in qt 4.6.
so tried again:
base_part->setflag(qgraphicsitem::itemnegativezstacksbehindparent); part_1->setflag(qgraphicsitem::itemnegativezstacksbehindparent); part_2->setflag(qgraphicsitem::itemnegativezstacksbehindparent);
using flag stacks part_1 , part_2 behind base_part still stack in front of base_parent.
i want know if there's way force items use z value , ignore parent child relationship.
the main reason insisting on hierarchical structure want animate base_part , part_1 , part_2 must move along base_part, of course know way around problem, if set parent of part_1 , part_2 base_parent, i'll able result wanted, have animate part_1 , part_2 little nasty.
Comments
Post a Comment