O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What just happened?

The first thing we did in the newly added code is call painter.save(). This call stores all parameters of the painter in an internal stack. We can then modify the painter state (by changing its attributes, applying transformations, and so on) and then, if at any point we want to go back to the saved state, it is enough to call painter.restore() to undo all the modifications in one go.

The save() and restore() methods can be called as many times as needed. States are stored in a stack, so you can save multiple times in a row and then restore to undo each change. Just remember to always pair a call to save() with a similar call to restore(), or the internal painter state will get corrupted. Each call to restore() will revert ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required