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
Forum Update on Monday, May 27th 2025

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 7 Sept 2017, 11:21 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?

    A 1 Reply Last reply 7 Sept 2017, 11:29
    0
    • F FOXLISIN
      7 Sept 2017, 11:21

      Hello!

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

      A Offline
      A Offline
      Arvindhan Ponnusamy
      wrote on 7 Sept 2017, 11:29 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 7 Sept 2017, 15:16 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
            }
        }
        
        A 2 Replies Last reply 8 Sept 2017, 04:27
        0
        • F FOXLISIN
          7 Sept 2017, 15:16

          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
              }
          }
          
          A Offline
          A Offline
          Arvindhan Ponnusamy
          wrote on 8 Sept 2017, 04:27 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
            7 Sept 2017, 15:16

            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
                }
            }
            
            A Offline
            A Offline
            Arvindhan Ponnusamy
            wrote on 8 Sept 2017, 05:00 last edited by Arvindhan Ponnusamy 9 Aug 2017, 05:08
            #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

            1/5

            7 Sept 2017, 11:21

            • Login

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