I'm creating some graphic data displaying widget in Qt4 and I was tempted to use the QGraphicsScene
for it, create QGraphicsItem
s for the data items etc.
However, I wanted to add some layer of controls (eg. scrollbars, zoom+other buttons - I want to make it in a similar style as eg. Google Maps, that is, the data would be displayed all over the widget, and the buttons would be shown atop of them) to the widget. So I thought it might be feasible to add them to the scene (perhaps as a child of a QGraphicsGroupItem
that would be shown over the data). But I want them to move & resize when I resize the whole widget, so I should use a QGraphicsLayout
for managing them. But at this point, I discovered things are pretty complicated.
The problem is that when using QGraphicsLayout
, the following constraints hold:
QGraphicsWidget
can be managed by a layoutQGraphicsLayout
can only be used to manage children of a QGraphicsWidget
Which means that I would have to create my controls as QGraphicsWidget
s, add a top level QGraphicsWidget
to the data widget, and manage the size of this top level widget myself.
So I want to ask:
Wouldn't a classic approach (ie. use plain old widgets for all controls, and use QGraphicsScene
only for displaying the data) be more reasonable?
Is there any advantage in using QGraphicsScene
in this case (performance or simplicity...)?
How should I use QGraphicsScene
to exploit its strengths?
Since Qt 4.4 you can embed classic widgets in a QGraphicsScene
by using QGraphicsProxyWidget
:
QWidget *widget = new QWidget;
QGraphicsScene scene;
QGraphicsProxyWidget *proxy = scene.addWidget(widget);