PDA

View Full Version : QGraphicsScene of the crime



baray98
8th November 2008, 19:51
Hi guys,

I was trying to add a wdiget on my scene using QGraphicsScene::addWidget() and one of the requirement of the widget to be added is "thou shall not be a child of any widget" . Now my question would be who's gonna clean up when the world ends. I will re-phrase my question "Will the QGraphicsScene own the widget and delete them as they go extinct?

baray98

Methedrine
9th November 2008, 12:06
When you use addWidget then you create a QGraphicsProxyWidget. And this is what the docs say on that class:


QGraphicsProxyWidget shares ownership with QWidget, so if either of the two widgets are destroyed, the other widget will be automatically destroyed as well.

QGraphicsProxyWidget again is derived from QGraphicsWidget, for which the docs say:



Although QGraphicsWidget inherits from both QObject and QGraphicsItem, you should use the functions provided by QGraphicsItem, not QObject, to manage the relationships between parent and child items. These functions control the stacking order of items as well as their ownership.

Note: The QObject:: parent() should always return 0 for QGraphicsWidgets, but this policy is not strictly defined.


This indicates that your widget is owned by your QGraphicsScene and thus should be destroyed by it.