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. How to access elements in a ListView's delegate?
Forum Updated to NodeBB v4.3 + New Features

How to access elements in a ListView's delegate?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 324 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.
  • T Offline
    T Offline
    t0m.n
    wrote on last edited by
    #1

    I have a ScrollView containing a ListView with a FolderListModel and some checkboxes like this. This gives a scrollable filesystem list with each row having a checkbox to the right.

    How can I access the checkboxes checked member for a given folderModel index (which is a certain row in the listView)? I'd like to check/uncheck certain checkboxes automatically.

    Thanks a lot!

    Window {
        visible: true
        width: 1920
        height: 1080
    
        FolderListModel {
            id: folderModel
            folder: "file:///home/pi/projects"
            rootFolder: "file:///home/pi/projetcs"
            showDirsFirst: true
            showDotAndDotDot: false
        }
    
        ScrollView {
            anchors.top: parent.top
            anchors.topMargin: 20
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            anchors.leftMargin: 20
            width: 800
            verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff
            horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
    
            ListView {
                id: listView
                model: folderModel
    
                delegate: RowLayout {
                    Rectangle {
                        Layout.leftMargin: 5
                        Layout.rightMargin: 15
                        color: folderModel.isFolder(index) ? "#666666" : "#AAAAAA"
                        border.width: 1
                        border.color: "#000000"
                        radius: 4
                        width: 650
                        height: 65
    
                        Text {
                            leftPadding: 10
                            height: parent.height
                            width: parent.width
                            color: "#FFFFFF"
                            y: parent.height / 2 - font.pixelSize / 2
                            text: fileName
                            bottomPadding: 10
                        }
                    }
    
                    CheckBox {
                        style: CheckBoxStyle {
                            indicator: Rectangle {
                                implicitWidth: 35
                                implicitHeight: 35
                                radius: 3
                                border.width: 1
    
                                Rectangle {
                                    visible: control.checked
                                    color: "lime"
                                    border.color: "#000000"
                                    radius: 1
                                    anchors.margins: 4
                                    anchors.fill: parent
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    
    ODБOïO 1 Reply Last reply
    0
    • T t0m.n

      I have a ScrollView containing a ListView with a FolderListModel and some checkboxes like this. This gives a scrollable filesystem list with each row having a checkbox to the right.

      How can I access the checkboxes checked member for a given folderModel index (which is a certain row in the listView)? I'd like to check/uncheck certain checkboxes automatically.

      Thanks a lot!

      Window {
          visible: true
          width: 1920
          height: 1080
      
          FolderListModel {
              id: folderModel
              folder: "file:///home/pi/projects"
              rootFolder: "file:///home/pi/projetcs"
              showDirsFirst: true
              showDotAndDotDot: false
          }
      
          ScrollView {
              anchors.top: parent.top
              anchors.topMargin: 20
              anchors.bottom: parent.bottom
              anchors.left: parent.left
              anchors.leftMargin: 20
              width: 800
              verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff
              horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
      
              ListView {
                  id: listView
                  model: folderModel
      
                  delegate: RowLayout {
                      Rectangle {
                          Layout.leftMargin: 5
                          Layout.rightMargin: 15
                          color: folderModel.isFolder(index) ? "#666666" : "#AAAAAA"
                          border.width: 1
                          border.color: "#000000"
                          radius: 4
                          width: 650
                          height: 65
      
                          Text {
                              leftPadding: 10
                              height: parent.height
                              width: parent.width
                              color: "#FFFFFF"
                              y: parent.height / 2 - font.pixelSize / 2
                              text: fileName
                              bottomPadding: 10
                          }
                      }
      
                      CheckBox {
                          style: CheckBoxStyle {
                              indicator: Rectangle {
                                  implicitWidth: 35
                                  implicitHeight: 35
                                  radius: 3
                                  border.width: 1
      
                                  Rectangle {
                                      visible: control.checked
                                      color: "lime"
                                      border.color: "#000000"
                                      radius: 1
                                      anchors.margins: 4
                                      anchors.fill: parent
                                  }
                              }
                          }
                      }
                  }
              }
          }
      }
      
      
      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      hi,
      @t0m-n said in How to access elements in a ListView's delegate?:

      I'd like to check/uncheck certain checkboxes automatically.

      You can do like this :

        property variant checkedBoxes : [true,false,true,false,true,false,true,false]...
      
        CheckBox {
             checked:checkedBoxes[index]
        }
      

      instead of accessing the objects directly.
      Then you just modify checkedBoxes .

      
       var newValues = []
       for (var i in checkedBoxes){
                      newValues[i] = false
                  }
       checkedBoxes = newValues
              
      
      1 Reply Last reply
      1
      • T Offline
        T Offline
        t0m.n
        wrote on last edited by
        #3

        Thanks, that helped!

        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