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 is getting black intermittently
Forum Update on Monday, May 27th 2025

QOpenGLWidget is getting black intermittently

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 1.1k 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.
  • S Offline
    S Offline
    Shivendra Pratap Singh
    wrote on last edited by JKSH
    #1

    [EDIT: Fixed title --JKSH]

    In my application we have created a dialog in which their are 2 section-
    Design-

    • First section contain the stackWidget consist of QGLWindow and QWidget.
    • Second section contain 4 buttons
      • When focus comes on the first button (Recording step) an specific ::Enter() is called in which we are showing the QGLWindow i.e paintGL is called.
      • On the same above-mentioned button when the focus leave an specified ::Leave() is called in which we are hiding the QGLWindow and showing the Qwidget i.e. paintEvent is called.
      • For other 3 buttons (Navigation button) when focus received on the we are just showing the QGLWindow and doing nothing application specific when the focus is moved out of them.

    Issue

    • Everything seems to be working fine but if you movefocus on above-mentioned 4 button very frequently say keep the keyboard arrow button pressed for a while, then all the previous pages which have QGLWindow stopped painting (i.e. GL window becomes black nothing is drawing) "their is no specific time when the issue is going to occur but it will occur thats for sure"

    • Once the GL window becomes black it remain black unless you restart the application or create a new patient file i.e. fresh navigation tree is created in which all the page and their data is delete and readded with new initialization.

    Solution

    • Though I have found the solution which is working i.e In ::Leave() of Recording Step i have removed the code which was responsible to hide the GLWindow and showing the QWidget, now only the GL window remain visible.
    • So now even if you move the focus very frequently on all 4 buttons the problem doesn't occur as GL window remain visible and only the GL scene is changing as the focus move from one button to other.

    What I need to know

    • What could be the root cause as I am unable to explain why hiding/showing the GLWindow and QWidget frequently is creating an issue.
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is a QGLWindow ? I know QWindow, the deprecated QGLWidget, QOpenGLWidget but not that one.

      Something is not clear on your description, how many of these do you have ?

      How are you implementing the switching ?

      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
      • S Offline
        S Offline
        Shivendra Pratap Singh
        wrote on last edited by
        #3

        Hi
        My mistake its QOpenGLWidget
        and we are using the QStackedWidget which consist of QOpenGLWidget and QWidget and for switching we are just changing the current index between 0 and 1
        i.e. GetDrawingArea()->setCurrentIndex( show ? 1 : 0 )
        here GetDrawingArea return stack 1 represent QOpenGLWidget and 0 represent QWidget

        hope it clarifies, feel free if any doubt in description
        highly appreciate any insight

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Do you have only one such QStackedWidget ?

          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
          • S Offline
            S Offline
            Shivendra Pratap Singh
            wrote on last edited by
            #5

            Yes, it is a common QStackedWidget that is used on all the pages of the application.
            we just change the gl_scene that needs to be drawn as per the particular page.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              So one single instance of it ?

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

              S 1 Reply Last reply
              0
              • JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by JoeCFD
                #7

                can you try to call update() of QOpenGLWidget to force repaint after switch?

                S 1 Reply Last reply
                0
                • SGaistS SGaist

                  So one single instance of it ?

                  S Offline
                  S Offline
                  Shivendra Pratap Singh
                  wrote on last edited by
                  #8

                  @SGaist Yes

                  1 Reply Last reply
                  0
                  • JoeCFDJ JoeCFD

                    can you try to call update() of QOpenGLWidget to force repaint after switch?

                    S Offline
                    S Offline
                    Shivendra Pratap Singh
                    wrote on last edited by
                    #9

                    @JoeCFD These things i have already tried like clean the GL the update, also like viewport update etc.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Would it be possible to create a minimal compilable example that triggers this issue ?

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

                      S 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Would it be possible to create a minimal compilable example that triggers this issue ?

                        S Offline
                        S Offline
                        Shivendra Pratap Singh
                        wrote on last edited by
                        #11

                        @SGaist Sorry actually it is not reproducible in a normal scenario.

                        Let me try to explain simply as I can.

                        • In our application, we are using a single StackWidget across the app the only thing that is changing is on every page we are creating a new QOpenGLWidget and new QWidget to attach to the stack for specified page in the application.
                        • Then we create a respecting GLDrawerScene for that widget.
                        • So in an erroneous scenario, we are moving on four buttons each having its own scene, for three buttons we are not trying to hide the GLWidget when we leave but in 1 particular button when we leave we hide the GLwidget.
                        • Right now we are on a model dialog but when we move the focus frequently on it the GLWidget in the back of the screen is getting black.
                        • And also if we move to previous pages their GL scene also becomes black and it remain black no matter what, if you want to correct the behaviour you need to restart the application.

                        My guess is paintGL and paintEvent calls are somehow getting into conflict and they stop drawing all together.

                        I want to know in what scenario this could happen like when can QOpenGLWidget becomes black.

                        and its not the graphic card issue else it would have come to any of the pages in the application rather than at specific step.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          How many QOpenGLWidget are you creating during an application run ?

                          Are you disposing of them ? If so how ?
                          Do you have specific resources associated with these widgets ?

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

                          S 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            How many QOpenGLWidget are you creating during an application run ?

                            Are you disposing of them ? If so how ?
                            Do you have specific resources associated with these widgets ?

                            S Offline
                            S Offline
                            Shivendra Pratap Singh
                            wrote on last edited by
                            #13

                            @SGaist
                            Sorry, it's getting very confusing right now for both of us.

                            Let me try to put my problem in a simple scenario-

                            If we create a QStackWidget and associate 2 pages with it 1- QOpenGLWidget 2-QWidget.

                            and try to hide/show QOpenGLWidget and QWidget very frequently for some time, is there a scenario where Qt stops drawing/painting altogether because in a gist this is what is happening.

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              It should not.

                              Since it does not happen in standard use, one way to find what might posing problem is to disable all the code that is not related to that widget.

                              Once that is done, gradually add bad stuff until it breaks again.

                              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

                              • Login

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