Important: Please read the Qt Code of Conduct -

[solved] How to define a custom group property?

  • This page in the documentation explains how to instantiate group properties (e.g. anchors{...}). It is silently about how to create your own grouped property, though.

    This QtBug page has been closed and states that apparently it is now possible to create your own grouped property. The question is: how???

    EDIT: For clarification: I basically want to transform this QML code snippet:

    property string recName;
    property int recSomeValue;
    property bool recSomeFlag;

    to something like this:

    property group rec
    string name;
    int someValue;
    bool someFlag;

    This syntax is completely fancied up. How do I write this in syntactically correct QML?

  • It's not directly what you want but a workaround: "here...":

  • Sure. That's how I worked it around; you linked to one of my own questions. :) However, grouping actual properties and having a JavaScript object that contains data is not the same! For instance, properties emit a onBlahChanged signal when their value change, while there is no such mechanism for the members of a JS object AFAIK.

    So, it would really be nice if there was a way to create custom group properties! Is it not possible then?

  • First sorry for that :) Another way, you can create your own group properties class. Create a class from QObject and register it as Qml Type. Now you can use your custom type as property type. The problem this is easy if you have fix properties because you can register it with Q_PROPERTY makro. If you want dynamic properties you need to handle it by your own. See an example "here...":

  • Hmm, ok, that might work. I hoped it would be simpler, though.

  • Hey, another idea. I'm not at home so i can't test it but what if you make something like this:
    Retangle {
    property Item rec: Item {
    property string recName: "" //for initialization
    property int recSomeValue: 0 //for initialization
    property bool recSomeFlag 0 //for initialization
    rec.onrecNameChanged: {
    console.log("yeah, it's changed");
    rec.recName: "bla"

  • Interesting idea! I'll check that out!

Log in to reply