[Gui]add support for QGraphicsObject to PythonWrapper

This commit is contained in:
Wanderer Fan
2022-05-07 15:24:12 -04:00
committed by WandererFan
parent 30b0efe025
commit ad64c57acd
2 changed files with 31 additions and 3 deletions

View File

@@ -26,6 +26,8 @@
# include <QDir>
# include <QIcon>
# include <QWidget>
# include <QGraphicsItem>
# include <QGraphicsObject>
#endif
#include <QMetaType>
@@ -368,7 +370,7 @@ QObject* PythonWrapper::toQObject(const Py::Object& pyobject)
QGraphicsItem* PythonWrapper::toQGraphicsItem(PyObject* pyPtr)
{
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
PyTypeObject* type = getPyTypeObjectForTypeName<QObject>();
PyTypeObject* type = getPyTypeObjectForTypeName<QGraphicsItem>();
if (type) {
if (Shiboken::Object::checkType(pyPtr)) {
SbkObject* sbkobject = reinterpret_cast<SbkObject*>(pyPtr);
@@ -385,6 +387,26 @@ QGraphicsItem* PythonWrapper::toQGraphicsItem(PyObject* pyPtr)
return nullptr;
}
QGraphicsObject* PythonWrapper::toQGraphicsObject(PyObject* pyPtr)
{
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
PyTypeObject* type = getPyTypeObjectForTypeName<QGraphicsObject>();
if (type) {
if (Shiboken::Object::checkType(pyPtr)) {
SbkObject* sbkobject = reinterpret_cast<SbkObject*>(pyPtr);
void* cppobject = Shiboken::Object::cppPointer(sbkobject, type);
return reinterpret_cast<QGraphicsObject*>(cppobject);
}
}
#else
// Access shiboken2/PySide2 via Python
//
void* ptr = qt_getCppPointer(Py::asObject(pyPtr), "shiboken2", "getCppPointer");
return reinterpret_cast<QGraphicsObject*>(ptr);
#endif
return nullptr;
}
Py::Object PythonWrapper::fromQIcon(const QIcon* icon)
{
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)