1

Some time ago I created a subclass of QGraphicsView that I called MultiWidget. Its purpose was to hold some other widgets I use, which I added with addWidget to the QGraphicsScene associated to my MultiWidget.

The idea was, that MultiWidget should present a "notebook like" view of all these added widgets, displaying them from top to bottom, one under the other and give (as an extra gimmick) a little green knob, with which the widget could be toggled between hidden and displayed:

enter image description here

Now I tried to add a new widget GPURenderWidget, derived from QOpenGLWidget with addWidget method of MultiWidget, which worked first seemingly without error. But: The content of the GPURenderWidget which is displayed through paintGL does not get displayed properly on the pane of the MultiWidget: An initial picture is shown, but albeit new frames are generated in a sequence of paintGL calls in GPURenderWidget, the view in MultiWidget does not get updated (the following is the still view that is presented):

enter image description here

I already set the viewport of my MultiWidget to OpenGL-form via

 setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));

Am I forced to abandon this approach? And what would be the best alternative? Should I create a GPURenderItem derived from QGraphicsItem and add that to QGraphicsView via addItem() ? But I would prefer to let GPURenderWidget remain a QOpenGLWidget so that it can be used as a standalone widget on other places. Or must I sacrifice the whole MultiWidget-approach with addWidget to a QGraphicsScene?

Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
Jürgen Böhm
  • 389
  • 3
  • 11

1 Answers1

2

The documentation for QGraphicsProxyWidget has a couple of notes/warnings, specifically...

Warning: This class is provided for convenience when bridging QWidgets and QGraphicsItems, it should not be used for high-performance scenarios. In particular, embedding widgets into a scene that is then displayed through a QGraphicsView that uses an OpenGL viewport will not work for all combinations.

and...

Note that widgets with the Qt::WA_PaintOnScreen widget attribute set and widgets that wrap an external application or controller cannot be embedded. Examples are QOpenGLWidget and QAxWidget.

So I think you're out of luck with regard embedding a QOpenGLWidget directly in a QGraphicsScene.

One possible alternative would be to use an framebuffer object for the OpenGL rendering and grab/blit the generated frames from the FBO to a simpler custom widget that can be embedded.

G.M.
  • 12,232
  • 2
  • 15
  • 18
  • Thank you for pointing out the cause of the problem - concerning your recommended alternative I would rather like to change the implementation of my MultiWidget not to use QGraphicsView and QGraphicsScene anymore. But what is the best alternative? Shall I create MultiWidget as a simple QWIdget (or QOpenGLWIdget?) with a QVBoxLayout in which I insert all the widgets (normal and OpenGL alike)? (tried this but discarded for speed reasons). There must be an effective solution, as notebook like interfaces that mix text and graphics are so popular, for example in computer algebra systems. – Jürgen Böhm Feb 06 '21 at 18:20
  • Actually the solution with a QWidget (I took a QScrollArea) and a QVBoxLayout worked out quite well know. The QOpenGLWidget was nicely rendered and displayed and the problems with speed I remembered to have had with this approach were now not existent. Just a good solution for collapsing and redisplaying single entries in the QVBoxLayout remains to be found, but I am optimistic. Maybe this QGraphicsView approach was "overengineered" to begin with. – Jürgen Böhm Feb 06 '21 at 21:44