Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. List view section from QStringList
Forum Updated to NodeBB v4.3 + New Features

List view section from QStringList

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 2 Posters 4.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mabrouk
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • I Offline
      I Offline
      ixSci
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mabrouk
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • I Offline
          I Offline
          ixSci
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mabrouk
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • I Offline
              I Offline
              ixSci
              wrote on last edited by
              #6

              past the full QML code you have, please

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mabrouk
                wrote on last edited by
                #7

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

                }@

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  ixSci
                  wrote on last edited by
                  #8

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

                  }@

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mabrouk
                    wrote on last edited by
                    #9

                    no errors, but also no sections appear

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved