Qt入门-单选框和复选框

来源:互联网 发布:软件分发平台 编辑:程序博客网 时间:2024/09/21 06:20

    在Qt GUI中,单选框类是QRadioButton,复选框类是QCheckBox。它们都是QAbstractButton的派生类。

(1)单选框

示例:

//设置为选择状态radioButton->setChecked(true);//返回选择状态bool radio_sel = radioButton->isChecked();

 

(2)复选框
 复选框不同于单选框,它有三种状态:checked、unchecked和PartiallyChecked。

Qt::Unchecked0The item is unchecked.Qt::PartiallyChecked1The item is partially checked. Items in hierarchical models may be partially checked if some, but not all, of their children are checked.Qt::Checked2The item is checked.

 

常用方法和属性如下:

//返回选择的状态Qt::CheckStatecheckState () const//是否处于PartiallyChecked状态boolisTristate () const//设置选择的状态,checked或uncheckedvoidsetCheckState ( Qt::CheckState state )//设置为PartiallyChecked状态voidsetTristate ( bool y = true )