如何强制QGLWidget更新屏幕? [英] How to force QGLWidget to update screen?

查看:389
本文介绍了如何强制QGLWidget更新屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Open GL绘制一个简单的场景。我已经子类化了QGLWidget和覆盖paintGL()。没有什么花哨那里:

I’m drawing a simple scene with Open GL. I’ve subclassed QGLWidget and overriden paintGL(). Nothing fancy there:

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();

 }



我在主窗口中有一个计时器,触发<$ c GLc小部件的$ c> updateGL()。我已经验证它导致 paintGL()被调用。然而,屏幕上的实际图片只是很少更新。即使我调整窗口大小,场景也不会更新。

I have a timer in main window which triggers updateGL() of GL widget. I’ve verified that it results in paintGL() being called. However, the actual picture on the screen is only updated very rarely. Even if I resize the window, scene is not updated. Why is that and how can I force it to update?

推荐答案

不要从你的计时器调用updateGL(),调用update (),以确保视图获取绘画事件。

Don't call updateGL() from your timer, call update() instead to ensure that the view gets a paint event.

这篇关于如何强制QGLWidget更新屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆