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. C++ listmodel with section.property
QtWS25 Last Chance

C++ listmodel with section.property

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 5 Posters 4.5k Views
  • 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.
  • L Offline
    L Offline
    lahianim
    wrote on last edited by
    #1

    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 that

    Thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dmcr
      wrote on last edited by
      #2

      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.

      dmcr

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lahianim
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • R Offline
          R Offline
          riaank
          wrote on last edited by
          #4

          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: parent

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

          1 Reply Last reply
          0
          • G Offline
            G Offline
            ggeorge82
            wrote on last edited by
            #5

            I have the same problem and i found solution - you should write
            section.property: "modelData.<propertyName>"

            F 1 Reply Last reply
            2
            • G Offline
              G Offline
              ggeorge82
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • G ggeorge82

                I have the same problem and i found solution - you should write
                section.property: "modelData.<propertyName>"

                F Offline
                F Offline
                FelixvdDonk
                wrote on last edited by
                #7

                @ggeorge82 Thank you, this fixed my issue

                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