0
votes

I'm having an issue where QGLWidget wants draw when added to a QTabWidget, but works as expected when added to the main window.

class GLView : public QGLWidget
{
    public:
       GLView(QWidget* parent = 0) : QGLWidget(parent)
       {
           QGLFormat format;
           format.setVersion(3, 3);
           format.setProfile(QGLFormat::CoreProfile);
           format.setSampleBuffers(true);

           setFormat(format);

           QTimer* timer = new QTimer(this);
           connect(timer, SIGNAL(timeout()), this, SLOT(updateGL()));
           timer->start(20);
      }

      void initializeGL()
      {
          funcs = new DrawFunctions();
          funcs->setCamera(&cam);
          glClearColor(1, 0, 0, 1);
      }

      void paintGL()
      {
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

         QVector<QVector2D> verts;
         verts.append(QVector2D(0, 0));
         verts.append(QVector2D(100, 0));
         verts.append(QVector2D(100, 100));
         verts.append(QVector2D(0, 100));

         funcs->solidPolygon(verts);

      }

      void resizeGL(int w, int h)
      {
         glViewport(0, 0, w, h);
         cam.setOrthographic(w, h);
      }

     Camera cam;
     DrawFunctions* funcs;
};

....

ui->tabWidget->addTab(new GLView(), "GLView);

DrawFunctions is subclassed from QOpenGLFunctions_3_3_Core, and the gl functions return no errors. I verified QOpenGLFunctions_3_3_Core::owningContext() equals the current Context.

I'm running on Windows 10. All help is appreciated.

EDIT: Upon further inspection, DrawFunction will draw a solidPolygon if I add another Tab, but it still does not draw correctly for the first tab.

1
Try with QOpenGLWidget, it interoperates with regular widgets much better than QGLWidget did. - Kuba hasn't forgotten Monica
Thanks for the reply but the result with QOpenGLWidget are the same - DevGuy
This might be a bug, then. Please turn your example into a single-file (just main.cpp) test case so that I could try reproducing. - Kuba hasn't forgotten Monica

1 Answers

0
votes

I think this might have something to do with it not being the topmost widget. I had problems with that. Check the debug output from your program. Also check for any debug output mentioning Parent widget.

Also, fire up a QOpenGLDebugLogger and see if it spits anything out. It's much more convenient than checkError.

I would also go for the newer QOpenGL*** classes as Kuba suggested, the QGL*** are deprecated.

Which version of Qt are you using?