From 3c3595e1e196204bfaec8c5f82db7f0fc84a1702 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Sun, 18 Apr 2021 18:58:18 +0200 Subject: 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 Reviewed-by: Cristian Maureira-Fredes --- examples/widgets/draganddrop/draggableicons/draggableicons.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'examples/widgets/draganddrop') diff --git a/examples/widgets/draganddrop/draggableicons/draggableicons.py b/examples/widgets/draganddrop/draggableicons/draggableicons.py index f8411de2e..5fe6590e7 100644 --- a/examples/widgets/draganddrop/draggableicons/draggableicons.py +++ b/examples/widgets/draganddrop/draggableicons/draggableicons.py @@ -152,6 +152,9 @@ class DragWidget(QFrame): child.show() child.setPixmap(pixmap) + # QPainter needs an explicit end() in PyPy. This will become a context manager in 6.3. + painter.end() + if __name__ == "__main__": app = QApplication(sys.argv) -- cgit v1.2.3