QRadioButton 類

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 是可以切換為開 (復選) 或關 (取消復選) 的選項按鈕。單選按鈕通常按多選一呈現給用戶。在一組單選按鈕中,每次僅一單選按鈕可被復選;若用戶選擇另一按鈕,先前選中按鈕切換為關。

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 ,和 組框範例 .

成員函數文檔編製

[explicit] QRadioButton:: QRadioButton ( QWidget * parent = nullptr)

構造單選按鈕采用給定 parent ,但沒有文本或像素圖。

The parent 自變量被傳遞給 QAbstractButton 構造函數。

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

構造單選按鈕采用給定 parent and text 字符串。

The parent 自變量被傳遞給 QAbstractButton 構造函數。

[虛擬] 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

初始化 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 .