Important: Please read the Qt Code of Conduct -

QOpenGlWidget format resetting when calling show()

  • Hi !

    I have noticed that pushing in QSurfaceFormat settings to my QOpenGlWidget gets resetted after i call show() on it. Is there a reason why this occurs and how do i prevent it?

        QSurfaceFormat glFormat;
        glFormat.setVersion(4, 5);
        glFormat.setSamples(4); //anti aliasing
        QApplication qapp(argc, argv);
        QOpenGLWidget* openGlWidget = new QOpenGLWidget();
        QSurfaceFormat format1 = openGlWidget->format();
        std::cout << format1.samples() << std::endl; //samples == 0 here, not 4
        return qapp.exec();

  • Lifetime Qt Champion


    Are you sure it is ?
    The call to show does not in fact show anything, it schedules a show event that will be processed by the event loop. Thus, your widget will not be shown until after app.exec() started.

  • Hi!

    I'm ofcourse not 100 % sure, i checked the source code and couldnt see that the method does apply anything on the QSurfaceFormat settings. However, i checked the value on the SurfaceFormat before and after the show() and it does indeed change at this method specifically. Any other source of reason why this is occuring? Why does the settings reset at all? How do i prevent it?

    Regards Dan

  • Lifetime Qt Champion

    That's my point: you do it too early. Call it after the widget has actually been shown. As I wrote before, calling show just schedule the widget to appear, it does not make it appear.

Log in to reply