QRadioButton Class

QRadioButton 提供一个带有文本标签的单选按钮. 更多...

头文件: #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 提供一个带有文本标签的单选按钮.

QRadioButton 是一个可以打开(选中)或关闭(未选中)的选择按钮. 单选按钮表示 "多种选项中选中一个选项" . 一组单选按钮仅能一次选中一个; 如果用户选择一个单选按钮, 自动清除之前选中的按钮.

单选按钮默认 自动互斥 . 如果开启自动互斥, 具有相同父对象的单选按钮自动互斥. 如果你需要为具有相同父对象的按钮创建多个互斥分组, 你可以使用 QButtonGroup.

一个按钮被打开或者关闭时会发送信号 toggled() . 如果你想在单选按钮每次状态更改时触发一个动作, 你可以连接这个信号. 使用 isChecked() 查询单选按钮是否被选中.

J类似 QPushButton, 单选按钮可以显示文本及可选的小图标. 调用 setIcon()设置图标. 采用构造函数传值或调用 setText()设置文本. 快捷键也是通过前缀&设置. 例如::


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

上述示例中, 快捷键是 Alt+A. 详见 QShortcut 文档. 使用'&&'显示&.

重要的继承函数: text(), setText(), text(), setDown(), isDown(), autoRepeat(), group(), setAutoRepeat(), toggle(), pressed(), released(), clicked(), and toggled().

Screenshot of a Fusion radio buttonA radio button shown in the Fusion widget style.
Screenshot of a Windows Vista radio buttonA radio button shown in the Windows Vista widget style.
Screenshot of a Macintosh radio buttonA radio button shown in the Macintosh widget style.

参见 QPushButton, QToolButton, QCheckBox, GUI Design Handbook: Radio Button, and Group Box Example.

成员函数

QRadioButton::QRadioButton(QWidget *parent = Q_NULLPTR)

Constructs a radio button with the given parent, but with no text or pixmap.

The parent argument is passed on to the QAbstractButton constructor.

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

Constructs a radio button with the given parent and text string.

The parent argument is passed on to the QAbstractButton constructor.

QRadioButton::~QRadioButton()

Destructor.

[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

Initialize option with the values from this QRadioButton. This method is useful for subclasses when they need a QStyleOptionButton, but don't want to fill in all the information themselves.

参见 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().