List view section from QStringList
-
wrote on 3 Jan 2012, 06:40 last edited by
Hi,
i made a list view in qml, which uses for model a QStinrgList like "this example":http://developer.qt.nokia.com/doc/qt-4.8/declarative-modelviews-stringlistmodel.html
and i want to make sections in the view for the first letter of the string item in the list, how can i do that ?
-
wrote on 3 Jan 2012, 07:11 last edited by
QString provided by the C++ side becomes JavaScript String so use its interface to access string content. For your case it will be just a list of str[0] where str is the string from the model you have passed to QML
-
wrote on 3 Jan 2012, 07:58 last edited by
well, i added the following on the previous example and didn't work
@section.criteria: ViewSection.FirstCharacter
section.property: myModel[0]
section.delegate: Rectangle{color: "green"; width: parent.width; height: 20}
@ -
wrote on 3 Jan 2012, 08:24 last edited by
obviously it doesn't work, you should use the model item not the model itself. See the example, link to which you have provided, it uses modelData for each created delegate not the myModel
-
wrote on 3 Jan 2012, 08:41 last edited by
well, i don't understand what you mean exactly
but i tried to replace myModel with modelData and it got me and error -
wrote on 3 Jan 2012, 08:46 last edited by
past the full QML code you have, please
-
wrote on 3 Jan 2012, 08:49 last edited by
here you are
@import QtQuick 1.0
ListView {
width: 100; height: 100
anchors.fill: parentmodel: myModel section.criteria: ViewSection.FirstCharacter section.property: medelData[0] section.delegate: Rectangle{color: "green"; width: parent.width; height: 20} delegate: Rectangle { height: 25 width: 100 Text { text: modelData } }
}@
-
wrote on 3 Jan 2012, 08:55 last edited by
try this out
@import QtQuick 1.0ListView {
width: 100; height: 100
anchors.fill: parent
model: myModelsection.criteria: ViewSection.FirstCharacter section.property: "modelData" section.delegate: Rectangle{color: "green"; width: parent.width; height: 20} delegate: Rectangle { height: 25 width: 100 Text { text: modelData } }
}@
-
wrote on 3 Jan 2012, 08:57 last edited by
no errors, but also no sections appear
7/9