Solved Resize and Item cretaed dynamically
-
Hi everyone,
when I create and object dynamically:var widgetTemp = Qt.createComponent("./RemoteWidgets/RoundButtonWidget.qml"); if (widgetTemp.status === Component.Ready) widgetsHolder.children.push( widgetTemp.createObject(container, { width: widgetsHolder.cellWidth, height: widgetsHolder.cellHeight}));
As you can see I set the width and the height in relation to another property.
My problem is that when this property changes (in this case widgetsHolder.cellWidth and widgetsHolder.cellHeight), my object not change its size.
I found some info in this link: http://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html
When managing dynamically created objects, you must ensure the creation context outlives the created object. Otherwise, if the creation context is destroyed first, the bindings in the dynamic object will no longer work.
But I don't know how to do it.
So, how it can be done?
Thank you -
I've just got the solution, Qt.binding (http://doc.qt.io/qt-5/qml-qtqml-qt.html#binding-method) has to be used:
var widgetTemp = Qt.createComponent("./RemoteWidgets/RoundButtonWidget.qml"); if (widgetTemp.status === Component.Ready) widgetsHolder.children.push( widgetTemp.createObject(container, { width: Qt.binding(function() { return widgetsHolder.cellWidth }), height: Qt.binding(function() { return widgetsHolder.cellHeight })})); }),