aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-09-30 14:10:42 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-10-27 16:36:49 +0000
commit1e6b06cec98f4467acfa25a95fbbcf240c3ddcf6 (patch)
tree0477c6f1b95c651bad950399e3810977bc511abf
parent07a93d22fd7f469e5e83ec454d6f90879e8cdb07 (diff)
Fix QIcon.addPixmap() to accept a PyPathLike argument
By modifying functions to accept a PyPathLike argument, we saw the side-effect of disabling implicit conversions. In an alternative branch, we tried to re-enable implicit conversion by adding new functions with a PyPathLike argument. This worked, but had drawbacks: * the signatures become redundant, and some post-processing must be implemented * the implicit conversion works fine, but only with a string argument. Much better would be to supply a PyPathLike This patch leaves the modifications of function arguments and simply adds the missing icon.addPixmap(PyPathLike). Other implicit conversions which might be found missing should be added the same way. [ChangeLog][shiboken6] The implicit conversion of icon.addPixmap(str) was replaced by an explicit version which takes PyPathLike. Change-Id: I48a2887e28473718f027059df2aafdd516f66dc3 Fixes: PYSIDE-1669 Task-number: PYSIDE-1499 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 3aab0899ef4f966d3a37c0e95b0e7d0f047de3e0) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml4
-rw-r--r--sources/pyside6/PySide6/glue/qtgui.cpp5
-rw-r--r--sources/pyside6/tests/QtGui/qicon_test.py20
3 files changed, 29 insertions, 0 deletions
diff --git a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
index b1d5ff585..bc2c0fb64 100644
--- a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
+++ b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
@@ -556,6 +556,10 @@
<parent index="this" action="add"/>
</modify-argument>
</modify-function>
+ <!-- PYSIDE-1669: Replace implicit conversion by a better explicit version -->
+ <add-function signature="addPixmap(PyPathLike@path@)">
+ <inject-code file="../glue/qtgui.cpp" snippet="qicon-addpixmap"/>
+ </add-function>
</value-type>
<value-type name="QPixmap" >
diff --git a/sources/pyside6/PySide6/glue/qtgui.cpp b/sources/pyside6/PySide6/glue/qtgui.cpp
index 81181dac4..39d5bf0ae 100644
--- a/sources/pyside6/PySide6/glue/qtgui.cpp
+++ b/sources/pyside6/PySide6/glue/qtgui.cpp
@@ -255,6 +255,11 @@ for (Py_ssize_t i = 0; i < count; ++i){
%0 = new %TYPE(QPixmap::fromImage(%1));
// @snippet qpixmap
+// @snippet qicon-addpixmap
+const auto path = PySide::pyPathToQString(%PYARG_1);
+%CPPSELF->addPixmap(path);
+// @snippet qicon-addpixmap
+
// @snippet qimage-decref-image-data
static void imageDecrefDataHandler(void *data)
{
diff --git a/sources/pyside6/tests/QtGui/qicon_test.py b/sources/pyside6/tests/QtGui/qicon_test.py
index 1387ff76b..2301793bc 100644
--- a/sources/pyside6/tests/QtGui/qicon_test.py
+++ b/sources/pyside6/tests/QtGui/qicon_test.py
@@ -48,5 +48,25 @@ class QIconCtorWithNoneTest(TimedQApplication):
self.app.exec()
+PIX_PATH = os.fspath(Path(__file__).resolve().parents[2]
+ / "doc/tutorials/basictutorial/icons.png")
+
+class QIconAddPixmapTest(TimedQApplication):
+ '''PYSIDE-1669: check that addPixmap works'''
+
+ def testQIconSetPixmap(self):
+ icon = QIcon()
+ icon.addPixmap(PIX_PATH)
+ sizes = icon.availableSizes()
+ self.assertTrue(sizes)
+
+ def testQIconSetPixmapPathlike(self):
+ icon = QIcon()
+ pix_path = Path(PIX_PATH)
+ icon.addPixmap(pix_path)
+ sizes = icon.availableSizes()
+ self.assertTrue(sizes)
+
+
if __name__ == '__main__':
unittest.main()