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.
QOpenGLWidget
, it interoperates with regular widgets much better thanQGLWidget
did. – Kuba hasn't forgotten Monica