List view section from QStringList



  • 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 ?



  • 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



  • 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}
    @



  • 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



  • well, i don't understand what you mean exactly
    but i tried to replace myModel with modelData and it got me and error



  • past the full QML code you have, please



  • here you are

    @import QtQuick 1.0

    ListView {
    width: 100; height: 100
    anchors.fill: parent

     model: 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 }
     }
    

    }@



  • try this out
    @import QtQuick 1.0

    ListView {
    width: 100; height: 100
    anchors.fill: parent
    model: myModel

     section.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 }
     }
    

    }@



  • no errors, but also no sections appear


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.