前言
CheckBox是一个提供可勾选的选项按钮,常用于各种设置界面,它既可以两态(checked/unchecked),也可以三态(checked/partial/unchecked)” 的开关控件。它还可以搭配了ButtonGroup 进行使用,代表同组按钮之间的多选、单选或互斥操作。
一、了解CheckBox

翻译一下:
CheckBox presents an option button that can be toggled on (checked) or off (unchecked). Check boxes are typically used to select one or more options from a set of options. For larger sets of options, such as those in a list, consider using CheckDelegate instead.
CheckBox inherits its API from AbstractButton. For instance, the state of the checkbox can be set with the checked property.
In addition to the checked and unchecked states, there is a third state: partially checked. The partially checked state can be enabled using the tristate property. This state indicates that the regular checked/unchecked state can not be determined; generally because of other states that affect the checkbox. This state is useful when several child nodes are selected in a treeview, for example.
二、简单实现
我们新建三个CheckBox看看效果:
ColumnLayout {
CheckBox {
checked: true
text: qsTr("First")
}
CheckBox {
text: qsTr("Second")
}
CheckBox {
checked: true
text: qsTr("Third")
}
}

可以看到Check自带有文本信息,我们可以进行自定义设置。同时,它还允许给定初始的checked值。
二、按钮组ButtonGroup
Column

QML的CheckBox&spm=1001.2101.3001.5002&articleId=153121356&d=1&t=3&u=edefa10cc28c4d89846e2d65d2e88b74)
861

被折叠的 条评论
为什么被折叠?



