QCheckBox 类

QCheckBox widget provides a checkbox with a text label. 更多...

头: #include <QCheckBox>
qmake: QT += widgets
继承: QAbstractButton

特性

公共函数

QCheckBox (QWidget * parent = Q_NULLPTR)
QCheckBox (const QString & text , QWidget * parent = Q_NULLPTR)
~QCheckBox ()
Qt::CheckState checkState () const
bool isTristate () const
void setCheckState (Qt::CheckState state )
void setTristate (bool y = true)

重实现公共函数

virtual QSize minimumSizeHint () const
virtual QSize sizeHint () const

信号

void stateChanged (int state )

保护函数

void initStyleOption (QStyleOptionButton * option ) const

重实现保护函数

virtual void checkStateSet ()
virtual bool event (QEvent * e )
virtual bool hitButton (const QPoint & pos ) const
virtual void mouseMoveEvent (QMouseEvent * e )
virtual void nextCheckState ()
virtual void paintEvent ( QPaintEvent * )

额外继承成员

详细描述

QCheckBox widget provides a checkbox with a text label.

A QCheckBox is an option button that can be switched on (checked) or off (unchecked). Checkboxes are typically used to represent features in an application that can be enabled or disabled without affecting others. Different types of behavior can be implemented. For example, a QButtonGroup 可以用于逻辑分组复选按钮,允许独占复选框。不管怎样, QButtonGroup 不提供任何视觉表示。

以下图像进一步阐明独占复选框和非独占复选框之间的差异。

每当复选框被复选或清零时,它发射信号 stateChanged ()。连接到此信号,若想要在复选框每次改变状态时触发动作。可以使用 isChecked () 查询复选框是否被复选。

In addition to the usual checked and unchecked states, QCheckBox optionally provides a third state to indicate "no change". This is useful whenever you need to give the user the option of neither checking nor unchecking a checkbox. If you need this third state, enable it with setTristate (),和使用 checkState () 查询当前触发状态。

就像 QPushButton ,复选框显示文本,及可选小图标。图标的设置是采用 setIcon ()。文本的设置可以在构造函数中或采用 setText ()。通过在首选字符之前加 & 号可以指定快捷键。例如:

QCheckBox *checkbox = new QCheckBox("C&ase sensitive", this);
					

在此范例中,快捷方式是 Alt+A 。见 QShortcut 文档编制了解细节。要显示实际和号,使用 &&。

重要继承函数: text (), setText (), text (), pixmap(), setPixmap(), accel(), setAccel(), isToggleButton(), setDown (), isDown (), isOn(), checkState (), autoRepeat (), isExclusiveToggle(), group (), setAutoRepeat (), toggle (), pressed (), released (), clicked (), toggled (), checkState (),和 stateChanged ().

另请参阅 QAbstractButton , QRadioButton ,和 GUI Design Handbook: Check Box .

特性文档编制

tristate : bool

此特性保持复选框是否为 3 态复选框

默认为 false,即:复选框只有 2 种状态。

访问函数:

bool isTristate () const
void setTristate (bool y = true)

成员函数文档编制

QCheckBox:: QCheckBox ( QWidget * parent = Q_NULLPTR)

构造复选框采用给定 parent ,但没有文本。

parent 被传递给 QAbstractButton 构造函数。

QCheckBox:: QCheckBox (const QString & text , QWidget * parent = Q_NULLPTR)

构造复选框采用给定 parent and text .

parent 被传递给 QAbstractButton 构造函数。

QCheckBox:: ~QCheckBox ()

析构函数。

Qt::CheckState QCheckBox:: checkState () const

返回复选框的复选状态。若不需要三态支持,还可以使用 QAbstractButton::isChecked (),其返回布尔。

另请参阅 setCheckState () 和 Qt::CheckState .

[virtual protected] void QCheckBox:: checkStateSet ()

重实现自 QAbstractButton::checkStateSet ().

[virtual protected] bool QCheckBox:: event ( QEvent * e )

重实现自 QObject::event ().

[virtual protected] bool QCheckBox:: hitButton (const QPoint & pos ) const

重实现自 QAbstractButton::hitButton ().

[protected] void QCheckBox:: initStyleOption ( QStyleOptionButton * option ) const

初始化 option 采用值来自此 QCheckBox 。此方法很有用对于子类要求 QStyleOptionButton ,但不想自己填充所有信息。

另请参阅 QStyleOption::initFrom ().

[virtual] QSize QCheckBox:: minimumSizeHint () const

重实现自 QWidget::minimumSizeHint ().

[virtual protected] void QCheckBox:: mouseMoveEvent ( QMouseEvent * e )

重实现自 QWidget::mouseMoveEvent ().

[virtual protected] void QCheckBox:: nextCheckState ()

重实现自 QAbstractButton::nextCheckState ().

[virtual protected] void QCheckBox:: paintEvent ( QPaintEvent * )

重实现自 QWidget::paintEvent ().

void QCheckBox:: setCheckState ( Qt::CheckState state )

将复选框的复选状态设为 state 。若不需要三态支持,还可以使用 QAbstractButton::setChecked (),其接受布尔。

另请参阅 checkState () 和 Qt::CheckState .

[virtual] QSize QCheckBox:: sizeHint () const

重实现自 QWidget::sizeHint ().

[signal] void QCheckBox:: stateChanged ( int state )

此信号被发射每当复选框状态改变时 (即:当用户复选或取消复选时)。

state 包含复选框的新 Qt::CheckState .