0

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.

enter image description here

Full source code is available here. https://github.com/syaifulnizamyahya/QT2dpainting

Syaiful Nizam Yahya
  • 4,196
  • 11
  • 51
  • 71
  • 1
    please provide a minimal working example with *all* the changes you made. – Eddy Alleman Aug 19 '19 at 13:35
  • I have provide full source code. The only changes I made is few lines in the main.cpp, which I already shown. – Syaiful Nizam Yahya Aug 20 '19 at 03:00
  • This appears to be more or less a dupe of your [previous question](https://stackoverflow.com/questions/57553945/how-to-add-qopenglwidget-to-qgraphicsscene) in which case the same [comment](https://stackoverflow.com/questions/57553945/how-to-add-qopenglwidget-to-qgraphicsscene#comment101571076_57553945) applies. – G.M. Aug 20 '19 at 10:53
  • @G.M. Yes it is. I did this because in my prev question, i have other errors. In here, I can make it more specific because there is only 1 changes. and no errors. Also, I have removed QGraphicsProxyWidget, I still get the same problem. – Syaiful Nizam Yahya Aug 21 '19 at 02:15
  • @EddyAlleman I have added working example. – Syaiful Nizam Yahya Aug 21 '19 at 02:16

1 Answers1

1

In the docs of QGraphicsProxyWidget *QGraphicsScene::addWidget(QWidget *widget, Qt::WindowFlags wFlags = Qt::WindowFlags())

Note that widgets with the Qt::WA_PaintOnScreen widget attribute set and widgets that wrap an external application or controller are not supported. Examples are QGLWidget and QAxWidget.

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.

Eddy Alleman
  • 1,096
  • 2
  • 10
  • 21