QGrahicsItem 及其子项
我现在已经尝试了几个小时来理解 QGraphicsItem 对于儿童的行为方式。我创建一个新的 QGraphicsItem B (实际上是它自己的子类),然后通过调用 B 上的 setParentItem 方法将其添加到另一个 QGraphicsItem A 作为子类。紧接着 A 将 B 作为子类。我已经使用一些迭代 A 的子级的调试代码进行了验证。然后 A 被添加到管理器中的 As 列表中。稍后在程序中,在 QWidget 中,从管理器获取列表迭代器。然后,我遍历 A 列表并检查每个子项,结果全部都消失了。我已经在调试器中验证了管理器确实是同一个实例,并且列表也是同一个实例。不知何故,这确实让我困惑,Qt FWK 中谁为我决定我的 A 对象不再需要它们的孩子?
我是 Qt 和 C++ 的新手,也拥有从 java 到 Objective-C 的丰富开发经验,所以我希望这是我不知道的 Qt 的专业,而不完全是我自己的愚蠢......
最好的问候,
安德烈
I have now tried for hours to make sense of how QGraphicsItem behaves with respect to children. I create a new QGraphicsItem B (actually an own subclass of it), and then add it to another QGraphicsItem A as child by invoking the setParentItem method on B. Immediately after that A has B as child. I have verified with some debug code that iterates over the children of A. Then A is added to a List of As in a Manager. Some time later in the program, in a QWidget the lists iterator is obtained from the manager. I then iterate over the list of As and check the children for each of them and all of them are gone. I have verified in the debugger that the Manager is really the same instance and the list is also the same instance. Somehow this really puzzles me, who in the Qt FWK decides for me that my A objects do no longer need their children?
I'm a newby to Qt and C++, also with extensive development experience from java to objective-c so I have some hope it is a speciality of Qt I'm not aware of, not entirely my own stupidity...
Best Regards,
André
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
供参考:
QGraphicsItemGroup 专门为分组而设计。
FYI:
QGraphicsItemGroup specially designed for grouping.