10

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

When is that, specifically?

Nomis Raserf
  • 123
  • 1
  • 4

1 Answers1

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! :-)

peppe
  • 19,728
  • 3
  • 47
  • 65
  • 1
    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()`. – Boris Dalstein Jul 18 '13 at 02:11
  • Thanks! I was not aware of the update() and updateGL() functions. Is this all from experience? – Nomis Raserf Jul 18 '13 at 15:29
  • Do you mean, if that's a complete list of when Qt asks for repaints, apart from user-generated ones (i.e. calling `update()`)? – peppe Jul 18 '13 at 16:04
  • I'm just wondering where you got your info, really, since I wasn't able to find anything about it online. :) – Nomis Raserf Jul 19 '13 at 13:49
  • 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.` – peppe Jul 19 '13 at 15:14
  • 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. – Nomis Raserf Jul 19 '13 at 16:06