QRadioButton 类

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

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

公共函数

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

重实现公共函数

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

静态公共成员

const QMetaObject staticMetaObject

保护函数

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

额外继承成员

详细描述

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

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

单选按钮是 autoExclusive 在默认情况下。若自动独占有启用,属于同一父级 Widget 的单选按钮行为就好像它们是同一独占按钮组的一部分。若需要多个属于同一父级 Widget 的单选按钮独占按钮组,将它们放入 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 ( QWidget * parent = nullptr)

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

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

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

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

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

[virtual] QRadioButton:: ~QRadioButton ()

析构函数。

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

重实现自 QAbstractButton::event ().

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

重实现自 QAbstractButton::hitButton ().

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

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

重实现自 QAbstractButton::paintEvent ().

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

重实现自 QWidget::sizeHint ().