You only need one QGraphicsScene , but the key here is that all QGraphicsItem and QGraphicsObject can be parent.
If you create a single QGraphicsItem or QGraphicsObject as the parent object, it does not need to draw anything, but it can be used as the root for the layer elements.
Therefore, a subclass of QGraphicsItem creates the QGraphicsItemLayer class, which does not display anything or add all the ellipses, polygons, etc. that are required on the same layer as the children of this QGraphicsItemLayer .
If you want to hide the layer, just hide the parent QGraphicsItemLayer object and all its children will be hidden too.
-------- Edited --------------
Inherit from QGraphicsItem : -
class QGraphicsItemLayer : public QGraphicsItem { public: virtual QRectF boundingRect() { return QRectF(0,0,0,0); } virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) { } };
Create a layer element:
QGraphicsItemLayer* pLayer = new QGraphicsItemLayer;
Add the objects you want to the layer, note that pLayer is passed as the parent
QGraphicsEllipseItem = new QGraphicsEllipseItem(pLayer);
Assuming you created a QGraphicsScene with a pointer to it named pScene : -
pScene->addItem(pLayer);
Then when you want to hide the layer
pLayer->hide();
Or display a layer: -
pLayer->show();