aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets/tutorials/cannon/t11.py
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2022-01-26 12:49:43 +0100
committerChristian Tismer <tismer@stackless.com>2022-01-26 16:47:13 +0000
commitb61f735acd8fa2e43a68d7d90f977d8f1506052a (patch)
tree9a5f4fb9debe1d7d51119ea9e169e58bc47bc62f /examples/widgets/tutorials/cannon/t11.py
parentdc2046124f132ba0187d1bff97364448288b1cd6 (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 <tismer@stackless.com>
Diffstat (limited to 'examples/widgets/tutorials/cannon/t11.py')
-rw-r--r--examples/widgets/tutorials/cannon/t11.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/examples/widgets/tutorials/cannon/t11.py b/examples/widgets/tutorials/cannon/t11.py
index ea8e53a8e..fa2198e10 100644
--- a/examples/widgets/tutorials/cannon/t11.py
+++ b/examples/widgets/tutorials/cannon/t11.py
@@ -159,13 +159,10 @@ class CannonField(QWidget):
self.update(region)
def paintEvent(self, event):
- painter = QPainter(self)
-
- self.paint_cannon(painter)
- if self._auto_shoot_timer.isActive():
- self.paint_shot(painter)
- # QPainter needs an explicit end() in PyPy. This will become a context manager in 6.3.
- painter.end()
+ with QPainter(self) as painter:
+ self.paint_cannon(painter)
+ if self._auto_shoot_timer.isActive():
+ self.paint_shot(painter)
def paint_shot(self, painter):
painter.setPen(Qt.NoPen)