jeudi 30 juillet 2020

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).

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

            }

        }
    }


}



Aucun commentaire:

Enregistrer un commentaire