QCheckBox 类

The QCheckBox 小部件提供带文本标签的复选框。 更多...

头: #include <QCheckBox>
继承: QAbstractButton

特性

公共函数

QCheckBox (QWidget * parent = 0)
QCheckBox (const QString & text , QWidget * parent = 0)
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 *)

额外继承成员

详细描述

The QCheckBox 小部件提供带文本标签的复选框。

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, but different types of behavior can be implemented. For example, a QButtonGroup 可以用于逻辑分组复选按钮,允许独占复选框。不管怎样, QButtonGroup 不提供任何视觉表示。

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

Whenever a checkbox is checked or cleared it emits the signal stateChanged ()。连接到此信号,若想要在复选框每次改变状态时触发动作。可以使用 isChecked () 查询复选框是否被复选。

除通常的复选和取消复选状态外, QCheckBox 还可选提供第 3 种 "无变化" 状态指示。这很有用每当需要赋予用户既不复选,也不取消复选的复选框选项时。若需要这种第 3 状态,启用它采用 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 ().

Screenshot of a Macintosh style checkbox A checkbox shown in the Macintosh widget style .
Screenshot of a Windows XP style checkbox A checkbox shown in the Windows XP widget style .
Screenshot of a Plastique style checkbox A checkbox shown in the Plastique widget style .

另请参阅 QAbstractButton , QRadioButton ,和 GUI 设计手册:复选框 .

特性文档编制

tristate : bool

This property holds whether the checkbox is a tri-state checkbox.

The default is false; i.e. the checkbox has only two states.

访问函数:

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

成员函数文档编制

QCheckBox:: QCheckBox ( QWidget * parent = 0)

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

parent 被传递给 QAbstractButton 构造函数。

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

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

parent 被传递给 QAbstractButton 构造函数。

Qt::CheckState QCheckBox:: checkState () const

Returns the check box's check state. If you do not need tristate support, you can also use QAbstractButton::isChecked () which returns a boolean.

另请参阅 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 ().

[虚拟] QSize QCheckBox:: minimumSizeHint () const

重实现自 QWidget::minimumSizeHint ().

该函数在 Qt 4.8 引入。

[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 )

Sets the check box's check state to state 。若不需要三态支持,还可以使用 QAbstractButton::setChecked () which takes a boolean.

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

[虚拟] QSize QCheckBox:: sizeHint () const

重实现自 QWidget::sizeHint ().

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

This signal is emitted whenever the check box's state changes, i.e. whenever the user checks or unchecks it.

state contains the check box's new Qt::CheckState .