QML学习笔记(三十三)QML的CheckBox

前言

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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值