paintEvent() vs render()
-
I've seen examples that mplement the painting logic in paintEvent(), and others that do it in render(). Which to choose? Perhaps a better question is what are the consideration in using one or the other, or even both?
Both methods sound pretty similar from the descriptions. And both are overloaded with various call signatures.
I'll be doing this from Python, with Qt5. Which I guess renders the issue of different function signatures somewhat moot.
Thanks
-
Hi,
The paintEvent method is to draw your widget. The render method is to paint your widget onto a specific target.
The former is the one that most people implement for their custom UIs. The later can be used for example when you want to render your widget when printing it.
[edit: Fixed wrong wording SGaist]
-
Thanks for your answer. I think I'm still missing something; I thought the painting process was device independent, so that putting an image on the screen and putting it on the printer were just a matter of swapping PaintDevice's, assuming one's painting logic adjusts for pixel density variation. But it sounds as if you're saying that painting the screen goes through different code in the QWidget than painting the printer.
I realize painting to the screen is potentially more dynamic as parts of the window are covered and uncovered.
-
By default paintEvent does nothing.
render is used to obtain the content of a widget. I just realized that it's also not virtual and thus you can't overload it.