QPainter painter; painter.save(); // draw something painter.restore(); // restores painter to previous state
QPainter painter; painter.setPen(Qt::red); painter.save(); painter.setPen(Qt::blue); // draw something painter.restore(); // pen color is now red againIn this example, we set the pen color to red using the setPen() function, then call the save() function. We then set the pen color to blue and do some drawing. After that, we call restore() and the pen color is now back to red. The QPainter save() function is part of the Qt graphical user interface library.