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