diff options
author | Friedemann Kleint <[email protected]> | 2025-06-06 10:52:24 +0200 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2025-06-06 11:32:37 +0200 |
commit | 6f996ff3439e69b3938e617135b266974802d5b1 (patch) | |
tree | d2e91448ae50940fb3bc8062f515c7c9b4b1dbe3 | |
parent | e38c671e249b2020261fb03ad568b8f4954e415a (diff) |
Fix QVariant conversion of Python classes inheriting QGraphicsProxyObject
The check needs to be more fine-grained since
Shiboken::ObjectType::getOriginalName() returns
"QGraphicsObject*" for Python-derived classes, also.
Amends f81fb9ee887d088e8988d743bb7cac4f781fff82.
Pick-to: 6.9
Fixes: PYSIDE-3115
Task-number: PYSIDE-3069
Change-Id: I4589ec85075e712ed1c66acfce257ff41d965ec4
Reviewed-by: Shyamnath Premnadh <[email protected]>
-rw-r--r-- | sources/pyside6/libpyside/pysidevariantutils.cpp | 8 | ||||
-rw-r--r-- | sources/pyside6/tests/QtWidgets/qgraphicsobjectreimpl_test.py | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/sources/pyside6/libpyside/pysidevariantutils.cpp b/sources/pyside6/libpyside/pysidevariantutils.cpp index 7dbfb3afc..729557919 100644 --- a/sources/pyside6/libpyside/pysidevariantutils.cpp +++ b/sources/pyside6/libpyside/pysidevariantutils.cpp @@ -125,8 +125,12 @@ QMetaType resolveMetaType(PyTypeObject *type) // PYSIDE-1887, PYSIDE-86: Skip QObject base class of QGraphicsObject; // it needs to use always QGraphicsItem as a QVariant type for // QGraphicsItem::itemChange() to work. - if (qstrcmp(typeName, "QGraphicsObject*") == 0) - ++i; + if (qstrcmp(typeName, "QGraphicsObject*") == 0 && size > 1) { + auto *firstBaseType = reinterpret_cast<PyTypeObject *>(PyTuple_GetItem(type->tp_bases, 0)); + const char *firstBaseTypeName = Shiboken::ObjectType::getOriginalName(firstBaseType); + if (firstBaseTypeName != nullptr && qstrcmp(firstBaseTypeName, "QObject*") == 0) + ++i; + } for ( ; i < size; ++i) { auto baseType = reinterpret_cast<PyTypeObject *>(PyTuple_GetItem(type->tp_bases, i)); const QMetaType derived = resolveMetaType(baseType); diff --git a/sources/pyside6/tests/QtWidgets/qgraphicsobjectreimpl_test.py b/sources/pyside6/tests/QtWidgets/qgraphicsobjectreimpl_test.py index 91b405aaf..7ae29d1f7 100644 --- a/sources/pyside6/tests/QtWidgets/qgraphicsobjectreimpl_test.py +++ b/sources/pyside6/tests/QtWidgets/qgraphicsobjectreimpl_test.py @@ -53,8 +53,16 @@ class QGraphicsObjectReimpl(UsesQApplication): # See also PYSIDE-1887, PYSIDE-3069 gobjA = GObjA() gobjA.setParentItem(w) + print(gobjA.parentItem()) self.assertIs(type(w), type(gobjA.parentItem())) + # PYSIDE-3115: QVariant conversion of the parent + # (Python class inheriting QGraphicsObject). + parentA = GObjA() + gobjA = GObjA() + gobjA.setParentItem(parentA) + self.assertIs(type(parentA), type(gobjA.parentItem())) + gobjB = GObjB() gobjB.setParentItem(w) self.assertIs(type(w), type(gobjB.parentItem())) |