aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets/state-machine/trafficlight/trafficlight.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/state-machine/trafficlight/trafficlight.py')
-rw-r--r--examples/widgets/state-machine/trafficlight/trafficlight.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/examples/widgets/state-machine/trafficlight/trafficlight.py b/examples/widgets/state-machine/trafficlight/trafficlight.py
index b5e975cfc..2a35d23ce 100644
--- a/examples/widgets/state-machine/trafficlight/trafficlight.py
+++ b/examples/widgets/state-machine/trafficlight/trafficlight.py
@@ -74,12 +74,10 @@ class LightWidget(QWidget):
def paintEvent(self, e):
if not self._on_val:
return
- painter = QPainter(self)
- painter.setRenderHint(QPainter.Antialiasing)
- painter.setBrush(self.color)
- painter.drawEllipse(0, 0, self.width(), self.height())
- # QPainter needs an explicit end() in PyPy. This will become a context manager in 6.3.
- painter.end()
+ with QPainter(self) as painter:
+ painter.setRenderHint(QPainter.Antialiasing)
+ painter.setBrush(self.color)
+ painter.drawEllipse(0, 0, self.width(), self.height())
on = Property(bool, is_on, set_on)