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. Identify first element of a section in a list view

Identify first element of a section in a list view

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

    Hello!
    Is it possible to determine if a list item element is the first item of a section? I tried using the index, but the index refers to the whole list view?

    Thanks

    ODБOïO 1 Reply Last reply
    0
    • R rramos

      Hello!
      Is it possible to determine if a list item element is the first item of a section? I tried using the index, but the index refers to the whole list view?

      Thanks

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      hi,
      @rramos said in Identify first element of a section in a list view:

      Is it possible to determine if a list item element is the first item of a section?

      ListView.previousSection !== ListView.section
      

      complete exeample

          Rectangle {
              id: container
              width: 300
              height: 360
      
              ListModel {
                  id: animalsModel
                  ListElement { name: "Ant"; size: "Tiny" }
                  ListElement { name: "Flea"; size: "Tiny" }
                  ListElement { name: "Parrot"; size: "Small" }
                  ListElement { name: "Guinea pig"; size: "Small" }
                  ListElement { name: "Rat"; size: "Small" }
                  ListElement { name: "Butterfly"; size: "Small" }
                  ListElement { name: "Dog"; size: "Medium" }
                  ListElement { name: "Cat"; size: "Medium" }
                  ListElement { name: "Pony"; size: "Medium" }
                  ListElement { name: "Koala"; size: "Medium" }
                  ListElement { name: "Horse"; size: "Large" }
                  ListElement { name: "Tiger"; size: "Large" }
                  ListElement { name: "Giraffe"; size: "Large" }
                  ListElement { name: "Elephant"; size: "Huge" }
                  ListElement { name: "Whale"; size: "Huge" }
              }
      
              // The delegate for each section header
              Component {
                  id: sectionHeading
                  Rectangle {
                      width: container.width
                      height: childrenRect.height
                      color: "lightsteelblue"
      
                      Text {
                          text: section
                          font.bold: true
                          font.pixelSize: 20
                      }
                  }
              }
      
              ListView {
                  id: view
                  anchors.top: parent.top
                  height: container.height
                  width: parent.width
                  model: animalsModel
                  delegate: Text {
                      text: name
                      font.pixelSize: 18
                      color: ListView.previousSection !== ListView.section ? "red" : "blue"
                  }
      
                  section.property: "size"
                  section.criteria: ViewSection.FullString
                  section.delegate: sectionHeading
              }
          }
      
      1 Reply Last reply
      1

      • Login

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