Qml-CheckBox的使用
CheckBox属性
CheckBox的继承关系: CheckBox – AbstractButton – Control – Item; CheckBox的属性主要继承于AbstractButton。 属性checkState :勾选状态,值为:Qt.Unchecked、Qt.Checked、Qt.PartiallyChecked 属性nextCheckState :定义一个回调函数,当勾选状态发生变化时,调用,返回下个状态。 属性tristate :是否使能CheckBox为三态勾选框,默认CheckBox是二态即(Qt.Checked 和Qt.Unchecked)两种状态之间切换。注意,当tristate 为true时,toggled()信号不会在发送。 注意:在使用CheckBox时,如果将checkable 属性设置为false,勾选将不生效。
CheckBox的实例代码
import QtQuick
import QtQuick. ControlsItem { anchors. fill: parentRow{ id: idRowanchors. top: parent. topanchors. left: parent. leftanchors. margins: 10 spacing: 10 CheckBox{ id: idCheck1text: "check1" checkState: Qt. Uncheckedtristate: true onClicked: { console. log ( "check1 clicked tristate = " ) ; console. log ( "indicator width = " , indicator. width) ; } onToggled: { console. log ( "check1 toggled " ) ; } } CheckBox{ id: idCheck2text: "check2" checkState: Qt. CheckednextCheckState: function ( ) { if ( checkState == Qt. Unchecked) return Qt. Checkedelse return Qt. Unchecked} onClicked: { console. log ( "check2 clicked tristate = " , tristate ? " true" : " false" ) ; } onToggled: { console. log ( "check2 toggled " , checked ? "checked " : "unchecked" ) ; } } }
}