When is QGLWidget's paintGL called?
Asked Answered
I

1

10

All I can find is "whenever the widget needs to be painted."

When is that, specifically?

Ironsmith answered 17/7, 2013 at 21:23 Comment(0)
R
19

When you call updateGL() on your widget (or update()), or just Qt decides to redraw your widget. Reasons why Qt might choose to ask for a redraw include:

  • your widget gets resized
  • your widget is hidden and shown again
  • your widget is minimized and then restored
  • something else is put in front of your widget and then moved away
  • the Moon is in the third quarter
  • a distant butterfly had flapped its wings
  • ...

In short, you have very little control about when Qt asks for a repaint. Just be sure to paint fast! :-)

Rubefaction answered 17/7, 2013 at 21:34 Comment(6)
Complimentary info: paintGL() is not even called "instantly" when you call updateGL(). Instead, Qt waits and call it later when appropriate, so that successive calls of updateGL() only result in one call of paintGL().Clever
Thanks! I was not aware of the update() and updateGL() functions. Is this all from experience?Ironsmith
Do you mean, if that's a complete list of when Qt asks for repaints, apart from user-generated ones (i.e. calling update())?Rubefaction
I'm just wondering where you got your info, really, since I wasn't able to find anything about it online. :)Ironsmith
Docs and source code. Docs say: Each widget performs all painting operations from within its paintEvent() function. This is called whenever the widget needs to be redrawn, either as a result of some external change or when requested by the application.Rubefaction
So I guess "some external change" in that quote could be expanded to "whatever external change Qt's implementers have decided requires a redraw". And it tends to be sensible, and the redraw is fast anyway so it doesn't matter that it's called often. And if I want to see the real nitty gritty details of when it repaints, I can check the source code.Ironsmith

© 2022 - 2024 — McMap. All rights reserved.