Exposing enum values in Qt Quick Designer (with a nice combobox)



  • Hi,

    I wrote a simple plugin that exposes an enum property. It's a QtQuick2 extension plugin, loaded dynamically, and described by a plugin.qmltypes file, autogenerated using qmlplugindump.

    Everything seems to work fine: I can use my QML custom widgets, I can assign the enum property in the QML, both via MyEnum.value1 or a string representing the enum value.

    What I don't know is how t oexpose the property "myenum" in the designer pane of Qt Creator (v2.6.83 from git 2.7) so I can choose its value from a combobox containing all the possible enum values.

    Am I missing something?

    MyItem.h

    @
    #include <QQuickItem>

    class MyItem : public QQuickItem
    {
    Q_OBJECT
    Q_DISABLE_COPY(MyItem)

    Q_PROPERTY(MyEnum myenum READ getMyEnum WRITE setMyEnum NOTIFY myEnumChanged DESIGNABLE true)
    Q_ENUMS(MyEnum)
    

    public:
    MyItem(QQuickItem *parent = 0);
    ~MyItem();

    enum MyEnum
    {
      value1 = 0,
      value2,
      value3
    };
    
    void setMyEnum(MyEnum myNewEnum);
    MyEnum getMyEnum() const;
    

    signals:
    void myEnumChanged(MyEnum);

    private:
    MyEnum m_myEnum;
    };

    QML_DECLARE_TYPE(MyItem)
    @

    plugins.qmltypes

    @
    Module {
    Component {
    name: "MyItem"
    defaultProperty: "data"
    prototype: "QQuickItem"
    exports: ["MyItem 1.0"]
    Enum {
    name: "MyEnum"
    values: {
    "value1": 0,
    "value2": 1,
    "value3": 2
    }
    }
    Property { name: "myenum"; type: "MyEnum" }
    Signal {
    name: "myEnumChanged"
    Parameter { type: "MyEnum" }
    }
    }
    }
    @



  • I would be interested in that too. If nothing else works I would expose it as an int and communicate the values by tooltip but that is a little bit unsatisfactory.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.