Redrawing QGLWidget with 3D+2D graphics
I have a QGLWidget
which draws both 3D and 2D graphics (just开发者_如何学运维 like in Qt's overpainting example).
The thing is after I added drawing 2D graphics (moved code from paintGL() to paintEvent(), etc.), the widget stopped redrawing most of the times. It didn't redraw after resiging, after loading, and so on. So I put repaint()
calls, it helped in some cases, but doesn't help in e.g. resizing.
So which function should I use to refresh the widget? Is it update()
or updateGL()
or repaint()
? Or maybe there is a way to set some mode to enable automatic redrawing after resizing/load/...?
Thanks.
You should usually use 'update', as this will allow multiple queued paint events to be 'collapsed' into a single event. The update method will call updateGL for QGLWidgets. The 'repaint' method should be used if you want an immediate repaint.
If you have hooked up a timer to periodically call 'update', then failure to repaint regularly usually indicates that you're putting stress on the CPU.
Posting some of the code might make it easier to understand issues with resize/initialisation.
精彩评论