Loading QML Components in a ListModel
-
Ok, I have fixed the issue. It's in the Main.qml:
@onReleased: {
if (grid.firstIndexDrag != -1)
{
var moveTo = grid.indexAt(mouseX, mouseY)
if (moveTo > grid.firstIndexDrag)
widgetModel.move(moveTo,grid.firstIndexDrag,1)
else
widgetModel.move(grid.firstIndexDrag,moveTo,1)
grid.firstIndexDrag = -1
}
}@
Works with 9 objects, 3 objects and your loader code now. It was just the method I was using to test it that was flawed. Dragging items up rather than down ;).If the location being moved to is larger, the position of the previous item has its index change before the action can be performed. Delayed movement would remove this issue.
The above code works too, though.
-
You're incredible. Works perfectly.
-
Here is one more stretch:
If my QML items are being loaded into my Gridview from a model:
@ListModel {
id: widgetdelegate
ListElement {
element: "WidgetLargeYield.qml"
value: "test"
}
ListElement {
element: "WidgetLargeMoisture.qml"
}
ListElement {
element: "WidgetLargeWeight.qml"
}
}
@Each one of those .qml elements has a text property alias. How do I pass on the value? Through the model or through the page with the gridview?
-
Well there are a few options.
Through model:
@ListElement {
element: "WidgetLargeYield.qml"
text: "Test"
}@
This can be referenced in GridView/DelegateThrough GridView as you said.
Also through the QML files and the delegate:
In WidgetLargeYield.qml:
@property string text: "Test"@
A lonevariableOR
@property alias text: TextEdit.text@
An alias to a member propertyThen, inside your delegate:
@ Loader { id: myLoader; source: element }@
You can now reference the text variable with myLoader.text in GridView, delegate and the widget QML file.