I am new in QML/Qt Quick and I want to use ListView which has a section property. Main goal was creating collapsible ListView on my UI. My problem is Section delegate LoadcaseListElement needs some data from ListView's model which is loadcaseModel in here. But I cannot access my ListView model from my Section Delegate Element LoadcaseListElement . (I can access it from ListView Delegate which is layerDelegateItem).
The simplified code snippet is here: (The snippet does not include all js functions, element properties, etc. to achive collapsing action in favor of clarity.)
ListModel {
id: loadcaseModel
ListElement {loadcaseId:"1"; name:"LC1_Honeycomb Radome LLD3"; plyCount:"7"; layerId: "5001"}
ListElement {loadcaseId:"1"; name:"LC1_Honeycomb Radome LLD3"; plyCount:"7"; layerId: "5002"}
}
ListView {
id: loadcaseListView
anchors.fill: parent
model: loadcaseModel
delegate: LayerDelegate {
id: layerDelegateItem
anchors {
left: parent.left
leftMargin: 2
right: parent.right
rightMargin: 2
}
}
section {
property: "loadcaseId"
criteria: ViewSection.FullString
delegate: LoadcaseListElement {
listElementLoadcaseNumber: model.loadcaseId
}
}
}
Thanks for your help...
Enes
CodePudding user response:
If the only data you need to access is the property that you are sectioning on, then you should be able to use the section
attached property mentioned in the docs:
section {
property: "loadcaseId"
criteria: ViewSection.FullString
delegate: LoadcaseListElement {
listElementLoadcaseNumber: section
}
}
UPDATE:
You're trying to use section
in a way that it wasn't intended, so you're running into obstacles. I recommend first organizing your model in a nested fashion. Then make your delegate smart enough to expand/hide its sub-list of elements. Here is an example that shows one way to do this.