简体   繁体   中英

add qgraphicsitem children to scene

I have a QgraphicsObject , and it has a list of Qgraphicsobject children list, I was wondering if there exists a way to add parent to scene and children list added automatically and when I remove parent item from scene all children removed? I want this because I want to add and remove item sever time but I don't want to handle children adding and removing, it's where I add child to my list:

myobject *c_object = new myobject(this); //I set parent item
m_advertisements.append(c_object);

QGraphicsItem :

Painting

Items are painted by the view, starting with the parent items and then drawing children , in ascending stacking order. You can set an item's stacking order by calling setZValue(), and test it by calling zValue(), where items with low z-values are painted before items with high z-values. Stacking order applies to sibling items; parents are always drawn before their children.

So, when you add an object (parent) with children they should be painted as described in docs. Children objects can not be painted if their parent was removed from scene.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM