QRadioButton 类

QRadioButton 小部件提供带文本标签的单选按钮。 更多...

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

公共函数

QRadioButton (const QString & text , QWidget * parent = nullptr)
QRadioButton (QWidget * parent = nullptr)
virtual ~QRadioButton ()

重实现公共函数

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

保护函数

void initStyleOption (QStyleOptionButton * option ) const

重实现保护函数

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

详细描述

QRadioButton 是可以切换为开 (复选) 或关 (取消复选) 的选项按钮。单选按钮通常按多选一呈现给用户。在一组单选按钮中,每次仅一单选按钮可被复选;若用户选择另一按钮,先前选中按钮切换为关。

Radio buttons are autoExclusive by default. If auto-exclusive is enabled, radio buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. If you need multiple exclusive button groups for radio buttons that belong to the same parent widget, put them into a QButtonGroup .

每当被切换为开 (或关) 时,按钮发射 toggled () 信号。连接到此信号,若想要在按钮每次改变状态时触发动作。使用 isChecked () 能查看是否选中特定按钮。

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

QRadioButton *button = new QRadioButton("Search from the &cursor", this);
					

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

重要继承成员: text (), setText (), text (), setDown (), isDown (), autoRepeat (), group (), setAutoRepeat (), toggle (), pressed (), released (), clicked (),和 toggled ().

另请参阅 QPushButton , QToolButton , QCheckBox , GUI Design Handbook: Radio Button ,和 组框范例 .

成员函数文档编制

QRadioButton:: QRadioButton (const QString & text , QWidget * parent = nullptr)

构造单选按钮采用给定 parent and text 字符串。

parent 自变量被传递给 QAbstractButton 构造函数。

QRadioButton:: QRadioButton ( QWidget * parent = nullptr)

构造单选按钮采用给定 parent ,但没有文本或像素图。

parent 自变量被传递给 QAbstractButton 构造函数。

[virtual] QRadioButton:: ~QRadioButton ()

析构函数。

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

重实现: QAbstractButton::event (QEvent *e).

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

重实现: QAbstractButton::hitButton (const QPoint &pos) const.

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

初始化 option 采用值来自此 QRadioButton 。此方法对子类是有用的,当需要 QStyleOptionButton ,但不希望自己填充所有信息。

另请参阅 QStyleOption::initFrom ().

[override virtual] QSize QRadioButton:: minimumSizeHint () const

重实现访问函数为特性: QWidget::minimumSizeHint .

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

重实现: QAbstractButton::mouseMoveEvent (QMouseEvent *e).

[override virtual protected] void QRadioButton:: paintEvent ( QPaintEvent * )

重实现: QAbstractButton::paintEvent (QPaintEvent *e).

[override virtual] QSize QRadioButton:: sizeHint () const

重实现访问函数为特性: QWidget::sizeHint .