Important: Please read the Qt Code of Conduct -

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 as qmlRegisterType<DPShip>("dpship", 1, 0, "DPShip");
    This works perfectly fine.

    I want to have border.width and border.color properties in QML for my class.
    So in DPShip.h I tried:

    struct borderStruct
        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_PROPERTY(borderStruct border READ border WRITE setBorder NOTIFY borderChanged)
        DPShip(QQuickItem *parent = Q_NULLPTR);
        QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData);
        borderStruct border() const;
        setBorder(const borderStruct& border);
        borderStruct border_obj;
        void borderChanged(const borderStruct &border);

    In QML I instantiate my item as DPShip { }, which works fine as mentioned above, also Qt Creator recognizes the border property, but no members, ie. in the editor I get the error: "border" does not have members. (M17) when I write border.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

Log in to reply