Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Uncheck/Check all checkboxes at once
Forum Updated to NodeBB v4.3 + New Features

Uncheck/Check all checkboxes at once

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.6k 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.
  • C Offline
    C Offline
    chilarai
    wrote on last edited by
    #1

    I want to check/uncheck all the remaining checkboxes on checking/unchecking of another checkbox (All option - the first checkbox in the listview).

    In QML such actions are handled using IDs and since my Listview is dynamically generated from a model, I am unable to generate IDs for the other checkboxes. Currently, my code only checks/unchecks the first checkbox in the list. Please point me what am I doing wrong

    import QtQuick 2.12
    import QtQuick.Controls 2.4
    import QtQuick.Layouts 1.3
    
    Page {
    
        id : somepageid
    
        ListView{
    
            id: multiSelectCheckList
            model: ["1", "2", "3", "4"]
            height: parent.height
            width: parent.width
    
            delegate: Column{
    
                height: 20
                width: parent.width
    
    
                // All checkbox option
    
                Loader{
    
                    id: loaderAll
                    height: 15
                    active: model.row === 0
                    sourceComponent:
    
                        CheckBox {
                        checked: true
                        text: "All"
                        indicator.width: 15
                        indicator.height: 15
    
                        onCheckStateChanged: {
                            // Here I want the check/uncheck feature
                            console.log("All", checked)
    
                            if(checked){
                                modelCheckBoxes.checked = true
                            } else{
                                modelCheckBoxes.checked = false
                            }
                        }
                    }
                }
    
                // These checkboxes need to be check/uncheck
                // on clicking the above checkbox
                CheckBox {
    
                    id: modelCheckBoxes
                    anchors.top: loaderAll.bottom
                    checked: true
                    text: modelData
                    indicator.width: 15
                    indicator.height: 15
    
                }
    
            }
        }
    
    
    }
    
    ODБOïO KroMignonK 2 Replies Last reply
    0
    • C chilarai

      I want to check/uncheck all the remaining checkboxes on checking/unchecking of another checkbox (All option - the first checkbox in the listview).

      In QML such actions are handled using IDs and since my Listview is dynamically generated from a model, I am unable to generate IDs for the other checkboxes. Currently, my code only checks/unchecks the first checkbox in the list. Please point me what am I doing wrong

      import QtQuick 2.12
      import QtQuick.Controls 2.4
      import QtQuick.Layouts 1.3
      
      Page {
      
          id : somepageid
      
          ListView{
      
              id: multiSelectCheckList
              model: ["1", "2", "3", "4"]
              height: parent.height
              width: parent.width
      
              delegate: Column{
      
                  height: 20
                  width: parent.width
      
      
                  // All checkbox option
      
                  Loader{
      
                      id: loaderAll
                      height: 15
                      active: model.row === 0
                      sourceComponent:
      
                          CheckBox {
                          checked: true
                          text: "All"
                          indicator.width: 15
                          indicator.height: 15
      
                          onCheckStateChanged: {
                              // Here I want the check/uncheck feature
                              console.log("All", checked)
      
                              if(checked){
                                  modelCheckBoxes.checked = true
                              } else{
                                  modelCheckBoxes.checked = false
                              }
                          }
                      }
                  }
      
                  // These checkboxes need to be check/uncheck
                  // on clicking the above checkbox
                  CheckBox {
      
                      id: modelCheckBoxes
                      anchors.top: loaderAll.bottom
                      checked: true
                      text: modelData
                      indicator.width: 15
                      indicator.height: 15
      
                  }
      
              }
          }
      
      
      }
      
      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      @chilarai hi
      can this simplify the whole thing ?

      ListView{
      
          id: multiSelectCheckList
          model: ["all","1", "2", "3", "4"]
          anchors.fill: parent
          delegate: Column{
              CheckBox {      
                  text: modelData
                  enabled: index === 0
                  checked: index === 0 ? true : multiSelectCheckList.itemAtIndex(0).children[0].checked
              }
          }
      }
      

      also you are using anchors in a Column there must be warnings/errors saying
      QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column. Column will not function.
      in your application output

      C 1 Reply Last reply
      1
      • C chilarai

        I want to check/uncheck all the remaining checkboxes on checking/unchecking of another checkbox (All option - the first checkbox in the listview).

        In QML such actions are handled using IDs and since my Listview is dynamically generated from a model, I am unable to generate IDs for the other checkboxes. Currently, my code only checks/unchecks the first checkbox in the list. Please point me what am I doing wrong

        import QtQuick 2.12
        import QtQuick.Controls 2.4
        import QtQuick.Layouts 1.3
        
        Page {
        
            id : somepageid
        
            ListView{
        
                id: multiSelectCheckList
                model: ["1", "2", "3", "4"]
                height: parent.height
                width: parent.width
        
                delegate: Column{
        
                    height: 20
                    width: parent.width
        
        
                    // All checkbox option
        
                    Loader{
        
                        id: loaderAll
                        height: 15
                        active: model.row === 0
                        sourceComponent:
        
                            CheckBox {
                            checked: true
                            text: "All"
                            indicator.width: 15
                            indicator.height: 15
        
                            onCheckStateChanged: {
                                // Here I want the check/uncheck feature
                                console.log("All", checked)
        
                                if(checked){
                                    modelCheckBoxes.checked = true
                                } else{
                                    modelCheckBoxes.checked = false
                                }
                            }
                        }
                    }
        
                    // These checkboxes need to be check/uncheck
                    // on clicking the above checkbox
                    CheckBox {
        
                        id: modelCheckBoxes
                        anchors.top: loaderAll.bottom
                        checked: true
                        text: modelData
                        indicator.width: 15
                        indicator.height: 15
        
                    }
        
                }
            }
        
        
        }
        
        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #3

        @chilarai said in Uncheck/Check all checkboxes at once:

        I want to check/uncheck all the remaining checkboxes on checking/unchecking of another checkbox (All option - the first checkbox in the listview).

        I think the best way to achieve this is to use ExclusiveGroup ==> https://doc.qt.io/qt-5/qml-qtquick-controls-exclusivegroup.html

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        C 1 Reply Last reply
        0
        • ODБOïO ODБOï

          @chilarai hi
          can this simplify the whole thing ?

          ListView{
          
              id: multiSelectCheckList
              model: ["all","1", "2", "3", "4"]
              anchors.fill: parent
              delegate: Column{
                  CheckBox {      
                      text: modelData
                      enabled: index === 0
                      checked: index === 0 ? true : multiSelectCheckList.itemAtIndex(0).children[0].checked
                  }
              }
          }
          

          also you are using anchors in a Column there must be warnings/errors saying
          QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column. Column will not function.
          in your application output

          C Offline
          C Offline
          chilarai
          wrote on last edited by
          #4

          @LeLev oh it is so simplified. Thanks a lot

          1 Reply Last reply
          0
          • KroMignonK KroMignon

            @chilarai said in Uncheck/Check all checkboxes at once:

            I want to check/uncheck all the remaining checkboxes on checking/unchecking of another checkbox (All option - the first checkbox in the listview).

            I think the best way to achieve this is to use ExclusiveGroup ==> https://doc.qt.io/qt-5/qml-qtquick-controls-exclusivegroup.html

            C Offline
            C Offline
            chilarai
            wrote on last edited by
            #5

            @KroMignon Thanks. I will look into this as well

            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