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 構造函數。

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