Exposing struct members to QML from derived QQuickItem-class
-
Hiall
I have a class deriving from QQuickItem with overloaded updatePaintNode among others ...
The class is registered asqmlRegisterType<DPShip>("dpship", 1, 0, "DPShip");
This works perfectly fine.I want to have
border.width
andborder.color
properties in QML for my class.
So in DPShip.h I tried:struct borderStruct { Q_GADGET Q_PROPERTY(qreal width MEMBER m_width) Q_PROPERTY(QColor color MEMBER m_color) qreal m_width; QColor m_color; }; class DPShip : public QQuickItem { Q_OBJECT Q_PROPERTY(borderStruct border READ border WRITE setBorder NOTIFY borderChanged) public: DPShip(QQuickItem *parent = Q_NULLPTR); protected: QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData); borderStruct border() const; setBorder(const borderStruct& border); private: borderStruct border_obj; signals: void borderChanged(const borderStruct &border); }
In QML I instantiate my item as
DPShip { }
, which works fine as mentioned above, also Qt Creator recognizes theborder
property, but no members, ie. in the editor I get the error:"border" does not have members. (M17)
when I writeborder.width
for instance.How do I do this?
-
@adaptine said in Exposing struct members to QML from derived QQuickItem-class:
我有一个从 QQuickItem 派生的类,其中包含重载的 updatePaintNode ......
该类被注册为qmlRegisterType<DPShip>("dpship", 1, 0, "DPShip");
这很好用。
我想为我的班级在 QML 中拥有border.width和border.color属性。
所以在 DPShip.h 我试过:Hi I also want to know that qgss series draws borders. Can I see your source code? thank you