QOpenGLWidget is not updated in QMainWindow

I have loaded a QOpenGLWidget promoted into my Window class with QtDesigner, inside a QMainWindow.

The widget display is fine, I can see the obj model in my mainwindow. My update() function from Window is called (I know from qDebug()).

However my OpenGLWidget can't seem to be repainted inside the mainwindow unless I interact with the mainwindow (for instance, resize it, or move it on my screen). I guess these interactions imply the repaint of the whole mainwindow.

I tryied to force the repaint of the whole mainwindow everytime the OpenGL Window is updated but I can't make this work.

update() function from window.cpp :

void Window::update()
{
qDebug() << "update" ;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_transform.rotate(5.0f, QVector3D(0.4f, 0.3f, 0.3f));
emit updated() ;

// Schedule a redraw
paintGL();
}

m_transform is my transformation matrix which rotates my obj model.

Redefinition of update() slot inside mainwindow.h, which is called :

void MainWindow::update() {
qDebug() << "update mainwindow";
this->repaint();
}

Connexion between signal and slot :

    QObject::connect(ui->GLWidget, SIGNAL(updated()), this, SLOT(update()));

Edit : paintGL function in window class :

void Window::paintGL()
{

qDebug() << "paintGl" ;
// Clear
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.2f, 1.0f);

// Render using our shader
m_program->bind();
m_program->setUniformValue(u_worldToCamera, m_camera.toMatrix());
m_program->setUniformValue(u_cameraToView, m_projection);
{
    m_program->setUniformValue(u_modelToWorld, m_transform.toMatrix());
    m_model.draw(m_program) ;
}
m_program->release();
qDebug() << "end paintGL";
}

I'm using Qt5.6 on QtCreator and OpenGL 3.3 on Ubuntu.

链接地址: http://www.djcxy.com/p/39302.html

上一篇: 如何在QWebView / QWebPage中获得焦点元素?

下一篇: QMainWindow中未更新QOpenGLWidget