简体   繁体   English

将qgraphicsitem子项添加到场景中

[英]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? 我有一个QgraphicsObject ,它有一个Qgraphicsobject子列表列表,我想知道是否有一种方法可以将父项添加到场景中并自动添加子列表,当我从场景中删除父项时所有子项都被删除了? 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 : 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. 您可以通过调用setZValue()来设置项目的堆叠顺序,并通过调用zValue()来测试它,其中具有低z值的项目在具有高z值的项目之前被绘制。 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. 如果父项已从场景中删除,则无法绘制子对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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