aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6')
-rw-r--r--sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml7
-rw-r--r--sources/pyside6/PySide6/glue/qtgui.cpp9
-rw-r--r--sources/pyside6/tests/QtWidgets/qpicture_test.py4
3 files changed, 18 insertions, 2 deletions
diff --git a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
index 4c5a794ea..f89dcc493 100644
--- a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
+++ b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
@@ -1892,6 +1892,7 @@
<!-- ### "setPaintDevice(QPaintDevice*)" is an internal method. -->
<modify-function signature="setPaintDevice(QPaintDevice*)" remove="all"/>
</object-type>
+
<object-type name="QPainter">
<extra-includes>
<include file-name="QPainterPath" location="global"/>
@@ -2028,6 +2029,12 @@
<insert-template name="fix_args,QRect*"/>
</inject-code>
</modify-function>
+ <add-function signature="__enter__()" return-type="QPainter">
+ <inject-code file="../glue/qtgui.cpp" snippet="qpainter-enter"/>
+ </add-function>
+ <add-function signature="__exit__(PyObject*,PyObject*,PyObject*)">
+ <inject-code file="../glue/qtgui.cpp" snippet="qpainter-exit"/>
+ </add-function>
</object-type>
<value-type name="QGenericMatrix" generate="no"/>
diff --git a/sources/pyside6/PySide6/glue/qtgui.cpp b/sources/pyside6/PySide6/glue/qtgui.cpp
index 5630406a4..16a10807a 100644
--- a/sources/pyside6/PySide6/glue/qtgui.cpp
+++ b/sources/pyside6/PySide6/glue/qtgui.cpp
@@ -577,6 +577,15 @@ const auto points = PySide::Numpy::xyDataToQPointFList(%PYARG_1, %PYARG_2);
%CPPSELF.%FUNCTION_NAME(%1.constData(), %1.size(), %2);
// @snippet qpainter-drawpolygon
+// @snippet qpainter-enter
+Py_INCREF(%PYSELF);
+pyResult = %PYSELF;
+// @snippet qpainter-enter
+
+// @snippet qpainter-exit
+%CPPSELF.end();
+// @snippet qpainter-exit
+
// @snippet qmatrix4x4
// PYSIDE-795: All PySequences can be made iterable with PySequence_Fast.
Shiboken::AutoDecRef seq(PySequence_Fast(%PYARG_1, "Can't turn into sequence"));
diff --git a/sources/pyside6/tests/QtWidgets/qpicture_test.py b/sources/pyside6/tests/QtWidgets/qpicture_test.py
index 9e1479dd8..7e4a6ca97 100644
--- a/sources/pyside6/tests/QtWidgets/qpicture_test.py
+++ b/sources/pyside6/tests/QtWidgets/qpicture_test.py
@@ -43,8 +43,8 @@ from PySide6.QtWidgets import QWidget
class MyWidget(QWidget):
def paintEvent(self, e):
- p = QPainter(self)
- p.drawPicture(0, 0, self._picture)
+ with QPainter(self) as p:
+ p.drawPicture(0, 0, self._picture)
self._app.quit()