[GUI]Add PySide unwrapper for QGraphicsItem

This commit is contained in:
wandererfan
2020-03-11 16:25:08 -04:00
committed by WandererFan
parent 436153807f
commit 5823fdaf8e
2 changed files with 27 additions and 0 deletions

View File

@@ -386,6 +386,31 @@ QObject* PythonWrapper::toQObject(const Py::Object& pyobject)
return 0;
}
QGraphicsItem* PythonWrapper::toQGraphicsItem(PyObject* pyPtr)
{
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
PyTypeObject* type = getPyTypeObjectForTypeName<QObject>();
if (type) {
if (Shiboken::Object::checkType(pyPtr)) {
SbkObject* sbkobject = reinterpret_cast<SbkObject*>(pyPtr);
void* cppobject = Shiboken::Object::cppPointer(sbkobject, type);
return reinterpret_cast<QGraphicsItem*>(cppobject);
}
}
#elif QT_VERSION >= 0x050000
// Access shiboken2/PySide2 via Python
//
void* ptr = qt_getCppPointer(Py::asObject(pyPtr), "shiboken2", "getCppPointer");
return reinterpret_cast<QGraphicsItem*>(ptr);
#else
// Access shiboken/PySide via Python
//
void* ptr = qt_getCppPointer(Py::asObject(pyPtr), "shiboken", "getCppPointer");
return reinterpret_cast<QGraphicsItem*>(ptr);
#endif
return nullptr;
}
Py::Object PythonWrapper::fromQIcon(const QIcon* icon)
{
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)

View File

@@ -26,6 +26,7 @@
#include <vector>
#include <QUiLoader>
#include <QGraphicsItem>
#include <Base/Factory.h>
#include <Base/PyObjectBase.h>
@@ -49,6 +50,7 @@ public:
bool toCString(const Py::Object&, std::string&);
QObject* toQObject(const Py::Object&);
QGraphicsItem* toQGraphicsItem(PyObject* ptr);
Py::Object fromQWidget(QWidget*, const char* className=0);
const char* getWrapperName(QObject*) const;
/*!