diff options
author | Christian Tismer <tismer@stackless.com> | 2021-04-18 18:58:18 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-01-24 22:51:06 +0000 |
commit | 735472a88b67e4f9871d922a6a46e43d91f36397 (patch) | |
tree | 1956503b79e2f403b9db09f07291713719ca9140 /examples/widgets/tutorials/cannon/t9.py | |
parent | 85fd2f6d3c2abc0763502c72071f5f548be9405c (diff) |
PyPySide: handle QPainter correctly with GC
While testing the examples with PyPy, a number of examples
used QPainter without explicitly calling painter.end() and
crashed.
This works in standard Python, but leaves the painter open
in other implementations, because the implicit deletion of
objects when going out of scope does not work in the
wrapper when garbage collection is used.
Fixed by providing the missing painter.end() calls.
This problem should finally be fixed by making QPainter a
context manager. The same approach was taken by Python.org and
the file open/close functions. The context manager was needed
for implementations like IronPython, Jython and PyPy.
[ChangeLog][PySide6] The examples were adapted to PyPy's
need to close QPainter, explicitly. Eventually, we may turn
this into a context manager.
Change-Id: I18eeeff7df800bafce91a1e5c98c469aa3bcc41b
Task-number: PYSIDE-535
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
(cherry picked from commit 3c3595e1e196204bfaec8c5f82db7f0fc84a1702)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples/widgets/tutorials/cannon/t9.py')
-rw-r--r-- | examples/widgets/tutorials/cannon/t9.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/examples/widgets/tutorials/cannon/t9.py b/examples/widgets/tutorials/cannon/t9.py index 36dcf8fb1..f18144310 100644 --- a/examples/widgets/tutorials/cannon/t9.py +++ b/examples/widgets/tutorials/cannon/t9.py @@ -124,6 +124,8 @@ class CannonField(QWidget): 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() class MyWidget(QWidget): |