onCheckedChanged vs onCheckStateChanged

Viewed 952

What is the difference between onCheckedChanged and onCheckStateChanged? Both yield the same result when I check/uncheck the box.

import QtQuick 2.12
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3

Page {

    id : somepageid


    CheckBox {
        checked: true
        text: qsTr("Check Me")
        indicator.width: 15
        indicator.height: 15

        onCheckedChanged: {
            console.log(checked)
        }

        onCheckStateChanged: {
            console.log(checked)
        }

    }
}

1 Answers

A CheckBox can have 3 or 2 states depending on whether the tristate property is true or not, respectively.

  • Unchecked,
  • PartiallyChecked, and
  • Checked

So onCheckedChanged only fires if it goes to Checked or Unchecked state, for example it does not fire if it goes from Unchecked to PartiallyChecked state, unlike onCheckStateChanged which is fired in all cases.

Related