How to force QGLWidget to update screen?
Solution 1
Don't call updateGL() from your timer, call update() instead to ensure that the view gets a paint event.
Solution 2
inside your CGLWidget constructor
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(10);
timer -> start(VALUE);
play with `VALUE 10 is just an example.
Adorn
Violet Giraffe
I'm from Kharkiv, Ukraine. My city is being destroyed every day. Help us defend: https://www.comebackalive.in.ua/donate PC enthusiast, C++ fan and C++ / Qt / Android software developer. Also <3 Arduino. Music and car addict. Reinventing various wheels in my spare time. A custom-made square wheel is like a tailored suit, wouldn't you agree? Why do I have more rep from questions than from answers? Because you don't learn by answering; you learn by asking questions :) Ongoing personal open-source projects: Dual-panel file manager for Windows / Linux / Mac
Updated on June 17, 2022Comments
-
Violet Giraffe almost 2 years
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(); }
I have a timer in main window which triggers
updateGL()
of GL widget. I’ve verified that it results inpaintGL()
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? -
Violet Giraffe about 11 yearsIt doesn't work,
paintGL()
is not called at all then. Tried calling both, too - also doesn't work. But thanks for the hint. -
Pete about 11 yearsTry sticking a breakpoint in QGLWidget::paintEvent and see if it gets there after calling update() and what happens after that.
-
Violet Giraffe about 11 yearsIt's only called when I resize the window.
-
Pete about 11 yearsHave you set any window flags in the constructor of your view? update SHOULD cause you to get a paint event at some point in the near future after calling it, providing you are letting the event loop run correctly and you have not disabled updates on the widget. Not getting a paint event is your problem.
-
Violet Giraffe about 11 yearsThanks a lot, found the problem! Was actually just a logical problem on my part, but your answers helped :)
-
activatedgeek almost 10 yearsHey, I have used this technique it works. Is there somehow I can immediately update the scene as soon as the previous scene is rendered because right now I have a bottleneck of 10ms from the timer. I can't go faster than that.
-
Adorn almost 10 yearsplay with `VALUE 10 is just an example. if u put 1 there, it would be 1ms, point is not however, when you want to refresh the screen, point is when your scene is ready..
-
activatedgeek almost 10 yearsExactly what I said. As soon as my scene is ready, I want update to be triggered.
-
Adorn almost 10 yearsthen make sure if you really need a timer. also
timer(0)
will shoot out the timer immediately -
activatedgeek almost 10 yearsWell, this is what I need to know, how do I remove the timer from the application itself. I would prefer not using it.
-
BjkOcean about 3 yearsWhat was the problem actually? I am having a similar problem and I couldn't figure it out. Thanks in advance.