QRadioButton 类

QRadioButton widget provides a radio button with a text label. 更多...

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

公共函数

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

重实现公共函数

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

保护函数

void initStyleOption (QStyleOptionButton * option ) const

重实现保护函数

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

额外继承成员

详细描述

QRadioButton widget provides a radio button with a text label.

A QRadioButton is an option button that can be switched on (checked) or off (unchecked). Radio buttons typically present the user with a "one of many" choice. In a group of radio buttons, only one radio button at a time can be checked; if the user selects another button, the previously selected button is switched off.

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 ( QWidget * parent = Q_NULLPTR)

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

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

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

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

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

QRadioButton:: ~QRadioButton ()

析构函数。

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

重实现自 QObject::event ().

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

重实现自 QAbstractButton::hitButton ().

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

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

另请参阅 QStyleOption::initFrom ().

[virtual] QSize QRadioButton:: minimumSizeHint () const

重实现自 QWidget::minimumSizeHint ().

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

重实现自 QWidget::mouseMoveEvent ().

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

重实现自 QWidget::paintEvent ().

[virtual] QSize QRadioButton:: sizeHint () const

重实现自 QWidget::sizeHint ().