QRadioButton Class
QRadioButton 控件提供了一个带有文本标签的单选按钮。更多内容...
| 标题: | #include <QRadioButton> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
| 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 |
受保护函数
| virtual 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 是一种单选按钮,可处于选中(勾选)或未选中(未勾选)状态。单选按钮通常为用户提供“多选一”的选择。在一组单选按钮中,同一时间只能选中一个单选按钮;如果用户选择另一个按钮,则先前选中的按钮将变为未选中状态。
单选按钮默认启用自动排他功能。如果启用了自动排他,属于同一父控件的单选按钮将表现得如同属于同一个排他按钮组。如果需要为属于同一父控件的单选按钮创建多个排他按钮组,请将它们放入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 。
成员函数文档
[explicit] QRadioButton::QRadioButton(QWidget *parent = nullptr)
根据给定的parent 创建一个单选按钮,但不包含文本或位图。
parent 参数将传递给QAbstractButton 的构造函数。
[explicit] QRadioButton::QRadioButton(const QString &text, QWidget *parent = nullptr)
根据给定的parent 和text 字符串构建一个单选按钮。
parent 参数将传递给QAbstractButton 构造函数。
[virtual noexcept] 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。
[virtual protected] void QRadioButton::initStyleOption(QStyleOptionButton *option) const
使用QRadioButton 中的值初始化option 。当子类需要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 的访问函数。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.