Qt入门-单选框和复选框

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


(1)单选框

  1. //设置为选择状态  

  2. radioButton->setChecked(true);  

  3. //返回选择状态  

  4. bool radio_sel = radioButton->isChecked();

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

  1. Qt::Unchecked   0   The item is unchecked.  

  2. Qt::PartiallyChecked    1   The item is partially checked. Items in hierarchical models may be partially checked if some, but not all, of their children are checked.  

  3. Qt::Checked 2   The item is checked. 


常用方法和属性如下:

[cpp] view plaincopy

  1. //返回选择的状态  

  2. Qt::CheckState  checkState () const  

  3. //是否处于PartiallyChecked状态  

  4. bool    isTristate () const  

  5. //设置选择的状态,checked或unchecked  

  6. void    setCheckState ( Qt::CheckState state )  

  7. //设置为PartiallyChecked状态  

  8. void    setTristate ( bool y = true )  


你可能感兴趣的:(Qt入门-单选框和复选框)