check/uncheck all problem
-
I have the following code to
check/uncheck all
other checkboxes in a listview. I am using theButtonGroup
component to achieve the same. It seems to achieve what it is intended to do but when Iuncheck 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 } } }
-
I have the following code to
check/uncheck all
other checkboxes in a listview. I am using theButtonGroup
component to achieve the same. It seems to achieve what it is intended to do but when Iuncheck 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 } } }
-
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?
@chilarai I have never used it actually but here is the description
https://doc.qt.io/qt-5/qml-qtquick-controls2-buttongroup.html#detailsfrom 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..
-
@chilarai I have never used it actually but here is the description
https://doc.qt.io/qt-5/qml-qtquick-controls2-buttongroup.html#detailsfrom 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..