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. check/uncheck all problem
Forum Updated to NodeBB v4.3 + New Features

check/uncheck all problem

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 703 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 chilarai
    #1

    I have the following code to check/uncheck all other checkboxes in a listview. I am using the ButtonGroup component to achieve the same. It seems to achieve what it is intended to do but when I uncheck all of them and scroll through the listview, a few of the items on the top and bottom of the list are automatically checked again. What could be wrong?

    import QtQuick 2.3
    import QtQuick.Controls 2.15
    
    
    Rectangle {
        id: win
        width: parent.width
        height: parent.height
        visible: true
    
    
        ButtonGroup {
               id: childGroup
               exclusive: false
               checkState: mainCheckBox.checkState
           }
    
           CheckBox {
               id: mainCheckBox
               checked: true
               text: "All"
               indicator.width: 15
               indicator.height: 15
               checkState: childGroup.checkState
           }
    
           ListView {
               id: multiSelectCheckList
               model: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40]
               height: parent.height
               width: parent.width
               anchors {
                   top: mainCheckBox.bottom
                   margins: 10
               }
    
               delegate: CheckBox {
                   id: modelCheckBoxes
                   checked: true
                   text: modelData
                   indicator.width: 15
                   indicator.height: 15
                   ButtonGroup.group: childGroup
               }
           }
    }
    
    
    ODБOïO 1 Reply Last reply
    0
    • C chilarai

      I have the following code to check/uncheck all other checkboxes in a listview. I am using the ButtonGroup component to achieve the same. It seems to achieve what it is intended to do but when I uncheck all of them and scroll through the listview, a few of the items on the top and bottom of the list are automatically checked again. What could be wrong?

      import QtQuick 2.3
      import QtQuick.Controls 2.15
      
      
      Rectangle {
          id: win
          width: parent.width
          height: parent.height
          visible: true
      
      
          ButtonGroup {
                 id: childGroup
                 exclusive: false
                 checkState: mainCheckBox.checkState
             }
      
             CheckBox {
                 id: mainCheckBox
                 checked: true
                 text: "All"
                 indicator.width: 15
                 indicator.height: 15
                 checkState: childGroup.checkState
             }
      
             ListView {
                 id: multiSelectCheckList
                 model: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40]
                 height: parent.height
                 width: parent.width
                 anchors {
                     top: mainCheckBox.bottom
                     margins: 10
                 }
      
                 delegate: CheckBox {
                     id: modelCheckBoxes
                     checked: true
                     text: modelData
                     indicator.width: 15
                     indicator.height: 15
                     ButtonGroup.group: childGroup
                 }
             }
      }
      
      
      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      hi
      you need a real model or an array where you save the state of every checkbox

      delegate: CheckBox {
                     id: modelCheckBoxes
                     checked: true // << access your array where the values are saved
      
      
      1 Reply Last reply
      1
      • C Offline
        C Offline
        chilarai
        wrote on last edited by
        #3

        But then do you mean to say the ButtonGroup component is of no use for such a case?

        Is it only good for Radio buttons?

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

          But then do you mean to say the ButtonGroup component is of no use for such a case?

          Is it only good for Radio buttons?

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

          @chilarai I have never used it actually but here is the description
          https://doc.qt.io/qt-5/qml-qtquick-controls2-buttongroup.html#details

          from a quick, look it allows you to have a mutually exclusive group of buttons but it does not dave anything to do with the way you handle your listview/model etc..

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

            @chilarai I have never used it actually but here is the description
            https://doc.qt.io/qt-5/qml-qtquick-controls2-buttongroup.html#details

            from a quick, look it allows you to have a mutually exclusive group of buttons but it does not dave anything to do with the way you handle your listview/model etc..

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

            @ODБOï noted and fixed as you have mentioned

            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