[solved] How to define a custom group property?
-
This page in the documentation http://qt-project.org/doc/qt-5/qtqml-syntax-objectattributes.html explains how to instantiate group properties (e.g. anchors{...}). It is silently about how to create your own grouped property, though.
This QtBug page https://bugreports.qt-project.org/browse/QTBUG-15269 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...":http://qt-project.org/forums/viewthread/46913/
-
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...":http://qt-project.org/doc/qt-5/properties.html
-
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"
}
@