Hi Patrik,
the sections of a QML list view only have a few attached properties that you can work with. I am not sure what your exact use-case is, but maybe this example can give you an idea what you could do. It uses the property used to build the section, in order to access data from the model again:
import QtQuick 2.5
import Felgo 3.0
App {
NavigationStack {
Page {
title: "Sections"
AppListView {
id: listview
model: ListModel {
id: animalsModel
ListElement { name: "Ant"; size: "Tiny" }
ListElement { name: "Flea"; size: "Tiny" }
ListElement { name: "Parrot"; size: "Small" }
ListElement { name: "Guinea pig"; size: "Small" }
ListElement { name: "Rat"; size: "Small" }
ListElement { name: "Butterfly"; size: "Small" }
ListElement { name: "Dog"; size: "Medium" }
ListElement { name: "Cat"; size: "Medium" }
ListElement { name: "Pony"; size: "Medium" }
ListElement { name: "Koala"; size: "Medium" }
ListElement { name: "Horse"; size: "Large" }
ListElement { name: "Tiger"; size: "Large" }
ListElement { name: "Giraffe"; size: "Large" }
ListElement { name: "Elephant"; size: "Huge" }
ListElement { name: "Whale"; size: "Huge" }
}
delegate: Text { text: name; font.pixelSize: 18 }
section.property: "size"
section.criteria: ViewSection.FullString
section.delegate: Component {
id: sectionHeading
Rectangle {
width: listview.width
height: childrenRect.height
color: "lightsteelblue"
Text {
text: section + " " + listview.countChildren(section)
font.bold: true
font.pixelSize: 20
}
}
}
function countChildren(search) {
var count = 0;
for(var i=0; i<animalsModel.count; i++) {
if(animalsModel.get(i)["size"] === search) {
count++;
}
}
return count;
}
}
}
}
}
I hope that may give you an idea. In general, such sections are not closely related to the model or single entries of it, they are only aware of the property used to build the sections pretty much.
Best,
Alex