How to get QGLWidget to refresh the screen?

Im draws a simple scene with Open GL. Ive subclassed QGLWidget and redefined paintGL (). Nothing special:

void CGLWidget::paintGL() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt (120.0, 160.0, -300.0, 0.0 + 120.0, 0.0 + 160.0, 2.0 - 300.0, 0.0, 1.0, 0.0); glScalef(1.0f/300.0f, 1.0f/300.0f, 1.0f/300.0f); glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(80.0, width()/(double)height(), 5.0, 100000.0); glMatrixMode(GL_MODELVIEW); glBegin(GL_POINTS); glColor3f(1.0f,0.6f,0.0f); glVertex3d(x, y, z); // ...drawing some more points... glEnd(); } 

I have a timer in the main window that calls updateGL() GL widgets. Ive confirmed that this leads to a call to paintGL() . However, the actual image on the screen is updated very rarely. Even if you resize the window, the scene does not update. Why is this and how can I get it to update?

+6
source share
2 answers

Do not call updateGL () from your timer; instead, call update () to ensure that the view receives the paint event.

+10
source

inside your CGLWidget constructor

 QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(update())); timer->start(10); timer -> start(VALUE); 

Playing with VALUE 10 is just an example.

Decorate

+8
source

All Articles