Qt World Summit: Register Today!


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.setProfile(QSurfaceFormat::CoreProfile);
        glFormat.setSamples(4); //anti aliasing
        QSurfaceFormat::setDefaultFormat(glFormat);
    
        QApplication qapp(argc, argv);
    
        QOpenGLWidget* openGlWidget = new QOpenGLWidget();
    
        openGlWidget->setFormat(glFormat);
    
        openGlWidget->show();
    
        QSurfaceFormat format1 = openGlWidget->format();
    
        std::cout << format1.samples() << std::endl; //samples == 0 here, not 4
    
        return qapp.exec();
    

  • Lifetime Qt Champion

    Hi,

    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.



  • Hi, I can't get anti-aliasing to work on QOpenGlWidget either and I noticed the exact same thing:
    The value of samples() is correct initially but gets reset.

    Since this thread also shows up on Google, I would like to ask if someone found a solution


Log in to reply