Changing QML property from C++ : how to change width of QML property?
-
I have a QML element connected to a C++ object with just one property: counter.
When I update the counter property from C++ I want to update the width of my QML element (it's a Rectangle).
I have tried:
@
Rectangle {
property int counter = model.counter
width: counter * 10
}
@The width does not change when I change the counter property... How come?
[edit: Highlight added / Denis Kormalev]
-
Try this:
@
Rectangle {
width: 10 * model.counter
}
@Are you sure that you are correctly exposing your c++ object to QML? I assumed in the above that your object is correctly exposed as model and that the property is called counter.
-
I think you've meant
@
Rectangle {
property int counter: model.counter
width: counter * 10
}
@
Do you change qml property or property of model from c++? If second, then you should use alias instead of full qml property. And don't forget about emitting signal on property change (one mentioned in NOTIFY).P.S. And please, don't forget to highlight your code