Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QOpenGlWidget format resetting when calling show()
Forum Update on Monday, May 27th 2025

QOpenGlWidget format resetting when calling show()

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 271 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johansson_gbg
    wrote on 5 Jun 2020, 12:22 last edited by
    #1

    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();
    
    1 Reply Last reply
    1
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 Jun 2020, 19:20 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        johansson_gbg
        wrote on 6 Jun 2020, 00:39 last edited by
        #3

        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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 6 Jun 2020, 17:35 last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maruker
            wrote on 23 Aug 2021, 11:31 last edited by
            #5

            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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved