aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-03-25 15:40:17 +0100
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-03-31 09:02:18 +0200
commit66e9e9e0674dff4ac0715faf17bf039eeb287df7 (patch)
tree1fedaff9980c869eabd7ecb275c31f8c9e28da20
parenta72239ef610940910b6375f638c0708cd1da97ff (diff)
PySide6: Fix QMetaProperty::Write(..)
Change 108d82d2ca5323652a50706b37f829b9f0457367 introduced a regression that when enum is passed to a QVariant and that QVariant is processed from C++, it does not work as expected. This patch handles the case of enum, separately for the function under consideration. Pick-to: 6.2 Task-number: PYSIDE-1870 Change-Id: I5d002cb36f23d8763de737578af7b52d8259a306 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/pyside6/PySide6/QtCore/typesystem_core_common.xml3
-rw-r--r--sources/pyside6/PySide6/glue/qtcore.cpp7
-rw-r--r--sources/pyside6/tests/QtWidgets/qvariant_test.py9
3 files changed, 18 insertions, 1 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
index 06d922851..65011a03e 100644
--- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
+++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
@@ -2936,6 +2936,9 @@
<value-type name="QMetaProperty" >
<!-- This isn't part of Qt public API -->
<modify-function signature="enclosingMetaObject()const" remove="all"/>
+ <modify-function signature="write(QObject*,const QVariant &amp;)const">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qmetaproperty_write_enum"/>
+ </modify-function>
</value-type>
<value-type name="QMetaClassInfo">
<!-- This isn't part of Qt public API -->
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp
index 7f0e7b91a..c2d714c9d 100644
--- a/sources/pyside6/PySide6/glue/qtcore.cpp
+++ b/sources/pyside6/PySide6/glue/qtcore.cpp
@@ -1574,3 +1574,10 @@ QString result;
QDebug(&result).nospace() << "<PySide6.QtCore.QEvent(" << %CPPSELF->type() << ")>";
%PYARG_0 = Shiboken::String::fromCString(qPrintable(result));
// @snippet repr-qevent
+
+// @snippet qmetaproperty_write_enum
+if (Shiboken::Enum::check(%PYARG_2)) {
+ int in = %CONVERTTOCPP[int](%PYARG_2);
+ cppArg1 = QVariant(in);
+}
+// @snippet qmetaproperty_write_enum
diff --git a/sources/pyside6/tests/QtWidgets/qvariant_test.py b/sources/pyside6/tests/QtWidgets/qvariant_test.py
index 927db4d54..c156cdc3f 100644
--- a/sources/pyside6/tests/QtWidgets/qvariant_test.py
+++ b/sources/pyside6/tests/QtWidgets/qvariant_test.py
@@ -38,7 +38,7 @@ init_test_paths(False)
from PySide6.QtCore import Qt, QObject
from PySide6.QtWidgets import (QComboBox, QGraphicsScene,
- QGraphicsRectItem, QComboBox)
+ QGraphicsRectItem)
from helper.usesqapplication import UsesQApplication
@@ -155,6 +155,13 @@ class QVariantConversionTest(UsesQApplication):
self.assertEqual(self.obj.property("test"), test)
self.assertTrue(isinstance(self.obj.property("test"), Test))
+ def testQMetaPropertyWrite(self):
+ combo_box = QComboBox()
+ meta_obj = combo_box.metaObject()
+ i = meta_obj.indexOfProperty("sizeAdjustPolicy")
+ success = meta_obj.property(i).write(combo_box, QComboBox.SizeAdjustPolicy.AdjustToContents)
+ self.assertTrue(success)
+
if __name__ == '__main__':
unittest.main()