diff options
Diffstat (limited to 'examples/widgets/tutorials/cannon/t10.py')
-rw-r--r-- | examples/widgets/tutorials/cannon/t10.py | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/examples/widgets/tutorials/cannon/t10.py b/examples/widgets/tutorials/cannon/t10.py index 98b5f57fe..0e553f8c5 100644 --- a/examples/widgets/tutorials/cannon/t10.py +++ b/examples/widgets/tutorials/cannon/t10.py @@ -129,17 +129,14 @@ class CannonField(QWidget): self.force_changed.emit(self._current_force) def paintEvent(self, event): - painter = QPainter(self) - - painter.setPen(Qt.NoPen) - painter.setBrush(Qt.blue) - - painter.translate(0, self.height()) - painter.drawPie(QRect(-35, -35, 70, 70), 0, 90 * 16) - painter.rotate(-self._current_angle) - painter.drawRect(QRect(33, -4, 15, 8)) - # QPainter needs an explicit end() in PyPy. This will become a context manager in 6.3. - painter.end() + with QPainter(self) as painter: + painter.setPen(Qt.NoPen) + painter.setBrush(Qt.blue) + + painter.translate(0, self.height()) + painter.drawPie(QRect(-35, -35, 70, 70), 0, 90 * 16) + painter.rotate(-self._current_angle) + painter.drawRect(QRect(33, -4, 15, 8)) def cannon_rect(self): result = QRect(0, 0, 50, 50) |