diff options
Diffstat (limited to 'examples/widgets/tutorials/cannon/t12.py')
-rw-r--r-- | examples/widgets/tutorials/cannon/t12.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/examples/widgets/tutorials/cannon/t12.py b/examples/widgets/tutorials/cannon/t12.py index 4960797bc..c503f9d5e 100644 --- a/examples/widgets/tutorials/cannon/t12.py +++ b/examples/widgets/tutorials/cannon/t12.py @@ -10,7 +10,7 @@ import math import random from PySide6.QtCore import QPoint, QRect, QTime, QTimer, Qt, Signal, Slot, qWarning -from PySide6.QtGui import QColor, QFont, QPainter, QPalette, QRegion +from PySide6.QtGui import QColor, QFont, QPainter, QPainterStateGuard, QPalette, QRegion from PySide6.QtWidgets import (QApplication, QGridLayout, QHBoxLayout, QLabel, QLCDNumber, QPushButton, QSlider, QVBoxLayout, QWidget) @@ -184,12 +184,11 @@ class CannonField(QWidget): painter.setPen(Qt.PenStyle.NoPen) painter.setBrush(Qt.GlobalColor.blue) - painter.save() - painter.translate(0, self.height()) - painter.drawPie(QRect(-35, -35, 70, 70), 0, 90 * 16) - painter.rotate(-self._current_angle) - painter.drawRect(CannonField.barrel_rect) - painter.restore() + with QPainterStateGuard(painter): + painter.translate(0, self.height()) + painter.drawPie(QRect(-35, -35, 70, 70), 0, 90 * 16) + painter.rotate(-self._current_angle) + painter.drawRect(CannonField.barrel_rect) def cannon_rect(self): result = QRect(0, 0, 50, 50) |