diff options
author | Christian Tismer <[email protected]> | 2022-01-26 12:49:43 +0100 |
---|---|---|
committer | Christian Tismer <[email protected]> | 2022-01-26 16:47:13 +0000 |
commit | b61f735acd8fa2e43a68d7d90f977d8f1506052a (patch) | |
tree | 9a5f4fb9debe1d7d51119ea9e169e58bc47bc62f /examples/widgets/tutorials/cannon/t10.py | |
parent | dc2046124f132ba0187d1bff97364448288b1cd6 (diff) |
examples: Turn most QPainter instances into context managers
After the new context manager is in place, most of
the examples benefit from moving QPainter into a
`with` statement.
The comments concerning PyPy could be removed, again.
[ChangeLog][PySide6] The examples are updated to use the new
context manager for QPainter.
Task-number: PYSIDE-535
Change-Id: Idf7e1f734d549ed663383ffbb2416297ebb1e0c7
Reviewed-by: Christian Tismer <[email protected]>
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) |