I based my implementation on this sample. https://doc.qt.io/qt-5/qtopengl-2dpainting-example.html
What the sample does is render/animate 2 images. One is rendered using native qt functionality and the other is rendered using OpenGL. Thats all there is to it. The image that is being drawn is exactly the same.
The sample works fine. I can see both images animate. Then when I try to make changes by adding a Window class (which contains the QOpenGLWidget) inside QGraphicsScene; QOpenGLWidget stops updating itself.
Original main.cpp
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSurfaceFormat fmt;
fmt.setSamples(4);
QSurfaceFormat::setDefaultFormat(fmt);
Window window;
window.show();
return app.exec();
}
Changed main.cpp
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSurfaceFormat fmt;
fmt.setSamples(4);
QSurfaceFormat::setDefaultFormat(fmt);
Window window;
//window.show();
QGraphicsScene scene;
scene.addWidget(&window);
scene.addText("Hello");
QGraphicsView view(&scene);
view.show();
return app.exec();
}
Here is the output.
Full source code is available here. https://github.com/syaifulnizamyahya/QT2dpainting
In the docs of QGraphicsProxyWidget *QGraphicsScene::addWidget(QWidget *widget, Qt::WindowFlags wFlags = Qt::WindowFlags())
I think you're out of luck. Could be the docs were never adapted when QOpenGLWidget was born.
Also there are some bugreports on Jira, that look very similar to your case: https://bugreports.qt.io/browse/QTBUG-44063
If I were you, to be sure I would ask on the interest mailinglists, that's where the Qt devs come regularly.