How to delete QGraphicsItem properly?

Unfortunately, QGraphicsItem is a base class of all graphics items usable inside QGraphicsScene, and, as most "item-like" objects in Qt, is not derived from QWidget or QObject. Moreover, they can only be parented to another QGraphicsItem (apart from being owned by QGraphicsScene.

After removing an item from a scene, unless it is parented to another QGraphicsItem, Qt expects the programmer to delete it manually by calling delete item; explicitly (or to use a smart pointer to manage the lifetime of the item after it was removed).

Tags:

Qt