Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Exposing enum values in Qt Quick Designer (with a nice combobox)
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Qt Creator and other tools
2 Posts 2 Posters 2.6k Views 1 Watching
  • 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.
  • crsnC Offline
    crsnC Offline
    crsn
    wrote on last edited by
    #1

    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" }
    }
    }
    }
    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexander.merkel
      wrote on last edited by
      #2

      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.

      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