diff options
author | Christian Tismer <[email protected]> | 2021-04-18 18:58:18 +0200 |
---|---|---|
committer | Christian Tismer <[email protected]> | 2022-01-24 19:29:23 +0100 |
commit | 3c3595e1e196204bfaec8c5f82db7f0fc84a1702 (patch) | |
tree | d6f9f64af8feb64c4d09960add362b806dea19b3 /examples/corelib | |
parent | 9b4d1f76128bc46a5ea85d33ce67f81029b8017e (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
Pick-to: 6.2
Task-number: PYSIDE-535
Reviewed-by: Friedemann Kleint <[email protected]>
Reviewed-by: Cristian Maureira-Fredes <[email protected]>
Diffstat (limited to 'examples/corelib')
-rw-r--r-- | examples/corelib/threads/mandelbrot.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/examples/corelib/threads/mandelbrot.py b/examples/corelib/threads/mandelbrot.py index c95966119..70658dc58 100644 --- a/examples/corelib/threads/mandelbrot.py +++ b/examples/corelib/threads/mandelbrot.py @@ -260,6 +260,8 @@ class MandelbrotWidget(QWidget): painter.setPen(Qt.white) painter.drawText(self.rect(), Qt.AlignCenter, "Rendering initial image, please wait...") + # QPainter needs an explicit end() in PyPy. This will become a context manager in 6.3. + painter.end() return if self._cur_scale == self._pixmap_scale: @@ -292,6 +294,8 @@ class MandelbrotWidget(QWidget): painter.setPen(Qt.white) painter.drawText((self.width() - text_width) / 2, metrics.leading() + metrics.ascent(), text) + # QPainter needs an explicit end() in PyPy. This will become a context manager in 6.3. + painter.end() def resizeEvent(self, event): self.thread.render(self._center_x, self._center_y, self._cur_scale, self.size()) |