Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Exposing struct members to QML from derived QQuickItem-class
Forum Updated to NodeBB v4.3 + New Features

Exposing struct members to QML from derived QQuickItem-class

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 311 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adaptine
    wrote on last edited by
    #1

    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_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 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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MKBK
      wrote on last edited by
      #2

      @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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved