Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-115652

Child quick widget fails to draw if it's child of raster native widget

    XMLWordPrintable

Details

    • 373c08d03 (dev), 56079c1a4 (6.5), 3e09f3abb (6.6)

    Description

      Please use this code to reproduce:

      #include <QtWidgets/QApplication>
      #include <QtWidgets/QWidget>
      #include <QtGui/QOpenGLFunctions>
      #include <QtGUI/QPainter>
      #include <QtOpenGLWidgets/QOpenGLWidget>
      
      class RedWidget : public QOpenGLWidget, protected QOpenGLFunctions
      {
      public:
          explicit RedWidget(QWidget* parent)
              : QOpenGLWidget(parent)
          {}
          void initializeGL() override
          {
              initializeOpenGLFunctions();
              glClearColor(1, 0, 0, 1);
          }
          void paintGL() override
          {
              glClear(GL_COLOR_BUFFER_BIT);
          }
      };
      
      class GreenWidget : public QOpenGLWidget, protected QOpenGLFunctions
      {
      public:
          explicit GreenWidget(QWidget* parent)
              : QOpenGLWidget(parent)
          {}
          void initializeGL() override
          {
              initializeOpenGLFunctions();
              glClearColor(0, 1, 0, 1);
          }
          void paintGL() override
          {
              glClear(GL_COLOR_BUFFER_BIT);
          }
      };
      
      int main(int argc, char** argv)
      {
          QApplication app(argc, argv);
      
          // tlw. By default, it's raster.
          QWidget tlw;
          tlw.resize(640, 480);
          tlw.winId();
      
          // OpenGL child of tlw. tlw is turned into OpenGL RHI.
          RedWidget red(&tlw);
          red.setGeometry(0, 0, 640, 160);
      
          // Raster native child of tlw. It's raster.
          QWidget blue_native(&tlw);
          blue_native.setStyleSheet("QWidget { background-color: blue; }");
          blue_native.setGeometry(0, 160, 640, 320);
          blue_native.winId();
      
          // OpenGL child of raster native child. setParent() checks the surface type of tlw. It's already OpenGL.
          // Backing store flush to blue_native instead of tlw. In this case, the window hierarchy is not
          // re-created. blue_native is still raster and fail to show green.
          GreenWidget green(&blue_native);
          green.setGeometry(0, 160, 640, 160);
      
          /*
           Expect result:
             ----------
                red
             ----------
                blue
             ----------
                green
           */
          /*
           Got:
             ----------
                red
             ----------
                blue
             ----------
                black
           */
      
          tlw.show();
          return app.exec();
      }
      

      In this kind of window hierarchy & widget creation order, the child quick widget fails to draw. setParent might need to check all parents towards tlw, instead of tlw only.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            lagocs Laszlo Agocs
            mingxiang Mingxiang Xu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: