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. ListView with sections and ObjectModel

ListView with sections and ObjectModel

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 1.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.
  • F Offline
    F Offline
    FOXLISIN
    wrote on last edited by
    #1

    Hello!

    I faced with next problem - i can't figure out how to use ListView with sections and ObjectModel.
    Is it possible?

    Arvindhan PonnusamyA 1 Reply Last reply
    0
    • F FOXLISIN

      Hello!

      I faced with next problem - i can't figure out how to use ListView with sections and ObjectModel.
      Is it possible?

      Arvindhan PonnusamyA Offline
      Arvindhan PonnusamyA Offline
      Arvindhan Ponnusamy
      wrote on last edited by
      #2

      @FOXLISIN Check this link
      http://doc.qt.io/qt-5/qml-qtquick-listview.html

      1 Reply Last reply
      0
      • F Offline
        F Offline
        FOXLISIN
        wrote on last edited by
        #3

        I have read this article. And i know how to use sections with ListModel, for example. But i dont know how to do it with ObjectModel:

        ListView {
            width: 500
            height: 1000
        
            model: ObjectModel {
                Rectangle {property string type: "first"; width: 500; height: 50}
                Rectangle {property string type: "first"; width: 500; height: 50}
                Rectangle {property string type: "second"; width: 500; height: 50}
                Rectangle {property string type: "second"; width: 500; height: 50}
            }
        
            section {
                section.property: ?????? //<-- should i write "type" here or what?
                criteria: ViewSection.FullString
                labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart
            }
        }
        
        Arvindhan PonnusamyA 2 Replies Last reply
        0
        • F FOXLISIN

          I have read this article. And i know how to use sections with ListModel, for example. But i dont know how to do it with ObjectModel:

          ListView {
              width: 500
              height: 1000
          
              model: ObjectModel {
                  Rectangle {property string type: "first"; width: 500; height: 50}
                  Rectangle {property string type: "first"; width: 500; height: 50}
                  Rectangle {property string type: "second"; width: 500; height: 50}
                  Rectangle {property string type: "second"; width: 500; height: 50}
              }
          
              section {
                  section.property: ?????? //<-- should i write "type" here or what?
                  criteria: ViewSection.FullString
                  labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart
              }
          }
          
          Arvindhan PonnusamyA Offline
          Arvindhan PonnusamyA Offline
          Arvindhan Ponnusamy
          wrote on last edited by
          #4

          @FOXLISIN : The below link explains how to use object models.
          http://doc.qt.io/qt-5/qml-qtqml-models-objectmodel.html
          Create object model separately for easy maintainability.

          1 Reply Last reply
          0
          • F FOXLISIN

            I have read this article. And i know how to use sections with ListModel, for example. But i dont know how to do it with ObjectModel:

            ListView {
                width: 500
                height: 1000
            
                model: ObjectModel {
                    Rectangle {property string type: "first"; width: 500; height: 50}
                    Rectangle {property string type: "first"; width: 500; height: 50}
                    Rectangle {property string type: "second"; width: 500; height: 50}
                    Rectangle {property string type: "second"; width: 500; height: 50}
                }
            
                section {
                    section.property: ?????? //<-- should i write "type" here or what?
                    criteria: ViewSection.FullString
                    labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart
                }
            }
            
            Arvindhan PonnusamyA Offline
            Arvindhan PonnusamyA Offline
            Arvindhan Ponnusamy
            wrote on last edited by Arvindhan Ponnusamy
            #5

            @FOXLISIN When an ObjectModel is used in a view, the view does not require a delegate since the ObjectModel already contains the visual delegate hence unable to get the property for creating the sections.

            I have tried in code but unable to create the sections.

            However it is easy to do while having list model with delegates.
            http://doc.qt.io/qt-5/qml-qtquick-listview.html#section-prop

            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