C++ listmodel with section.property
-
Hi all
ListView has section.property to devide the listmodel to sections
i need to create a c++ list model (of QString data) that support this section.property
how can i do thatThanks
-
QStringList coupled with setContextProperty to use it in QML side (perhaps with some javascript for displaying the string you select).
Otherwise you can use a hidden ListView and use its model to display the one you need.
-
Thanks for your answer.
maybe i was not clear.
i have a cpp model using QAbstractListModel and i use it in QML files and it works ok
BUT
i want to have the section attribute that ListView have in QML and i dont know how to implement it in the QAbstractListModel
do i need to implement the headerData method in the QAbstractListModel?? -
Just to clarify in QML
section.property holds the name of the property that is the basis of each section.If you look at the example in "QML Data Models":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativemodels.html#qabstractitemmodel it shows that the roles in the c++ model is used in QML. In the example the roles are "type" and "size". So if you want to create a section base on "type" you would alter the QML example (in the link) to:
@ListView {
width: 200; height: 250
anchors.fill: parentmodel: myModel delegate: Text { text: "Animal: " + type + ", " + size } section.property: type
}@
Hope that is what you are looking for. The above snippet is untested of course
-
I have the same problem and i found solution - you should write
section.property: "modelData.<propertyName>" -
This post is deleted! -
@ggeorge82 Thank you, this fixed my issue