Game Programming using Qt 5 Beginner's Guide - Second Edition
by Pavel Strakhov, Witold Wysota, Lorenz Haas
Optimizing the view
Since we are talking about the item's paint() function, let's touch on something related. By default, the view ensures that the painter state is saved before calling the item's paint function and that the state gets restored afterward. This will end up saving and restoring the painter state, say 50 times, if you have a scene with 50 items. However, you can disable this behavior by calling setOptimizationFlag(DontSavePainterState, true) on the view. If you do this, it is now your responsibility to ensure that any paint() function that changes the state of the painter (including pen, brush, transformation, and many other properties) must restore the previous state at the end. If you prevent automatic saving and restoring, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access