painter.save() --> saves the state
...
set some pens and brushes, do some painting
...
painter.restore() --> restores the state