QButtonGroup 類

The QButtonGroup 類提供用於組織按鈕 Widget 組的容器。 更多...

頭: #include <QButtonGroup>
繼承: QObject

特性

公共函數

QButtonGroup (QObject * parent = 0)
~QButtonGroup ()
void addButton (QAbstractButton * button )
void addButton (QAbstractButton * button , int id )
QAbstractButton * button (int id ) const
QList<QAbstractButton *> buttons () const
QAbstractButton * checkedButton () const
int checkedId () const
bool exclusive () const
int id (QAbstractButton * button ) const
void removeButton (QAbstractButton * button )
void setExclusive (bool)
void setId (QAbstractButton * button , int id )

信號

void buttonClicked (QAbstractButton * button )
void buttonClicked (int id )
void buttonPressed (QAbstractButton * button )
void buttonPressed (int id )
void buttonReleased (QAbstractButton * button )
void buttonReleased (int id )

額外繼承成員

詳細描述

The QButtonGroup 類提供用於組織按鈕 Widget 組的容器。

QButtonGroup 提供可以在其中放置按鈕 Widget 的抽象容器。它不提供這種容器的視覺錶示 (見 QGroupBox 瞭解容器 Widget),但代替管理組中每個按鈕的狀態。

An exclusive button group switches off all checkable (toggle) buttons except the one that was clicked. By default, a button group is exclusive. The buttons in a button group are usually checkable QPushButton 's, QCheckBox (通常用於非獨占按鈕組),或 QRadioButton 。若創建獨占按鈕組,應確保組中某一按鈕被最初復選;否則,組最初將處於未復選按鈕的狀態下。

A button is added to the group with addButton (). It can be removed from the group with removeButton (). If the group is exclusive, the currently checked button is available as checkedButton (). If a button is clicked the buttonClicked () signal is emitted. For a checkable button in an exclusive group this means that the button was checked. The list of buttons in the group is returned by buttons ().

此外, QButtonGroup 可以在整數和按鈕之間映射。可以將整數 ID 賦值給按鈕采用 setId (),和檢索它采用 id ()。目前獲得復選按鈕的 ID 是采用 checkedId (),且存在的重載信號 buttonClicked () 會發射按鈕的 ID。ID -1 被預留由 QButtonGroup 意味著 "沒有這種按鈕"。映射機製的目的是簡化用戶界麵枚舉值的錶示。

另請參閱 QGroupBox , QPushButton , QCheckBox ,和 QRadioButton .

特性文檔編製

exclusive : bool

This property holds whether the button group is exclusive.

If this property is true then only one button in the group can be checked at any given time. The user can click on any button to check it, and that button will replace the existing one as the checked button in the group.

在獨占組中,用戶無法通過點擊目前被復選的按鈕來取消復選;相反,必須點擊組中的另一按鈕來為該組設置新的被復選按鈕。

默認情況下,此特性為 true。

訪問函數:

bool exclusive () const
void setExclusive (bool)

成員函數文檔編製

QButtonGroup:: QButtonGroup ( QObject * parent = 0)

構造新的空按鈕組采用給定 parent .

另請參閱 addButton () 和 setExclusive ().

QButtonGroup:: ~QButtonGroup ()

銷毀按鈕組。

void QButtonGroup:: addButton ( QAbstractButton * button )

添加給定 button to the end of the group's internal list of buttons. An id will be assigned to the button by this QButtonGroup . Automatically assigned ids are guaranteed to be negative, starting with -2. If you are also assigning your own ids, use positive values to avoid conflicts.

另請參閱 removeButton () 和 buttons ().

void QButtonGroup:: addButton ( QAbstractButton * button , int id )

添加給定 button to the button group, with the given id . It is recommended to assign only positive ids.

另請參閱 removeButton () 和 buttons ().

QAbstractButton * QButtonGroup:: button ( int id ) const

返迴的按鈕具有指定 id ,或 0 若不存在這種按鈕。

該函數在 Qt 4.1 引入。

[signal] void QButtonGroup:: buttonClicked ( QAbstractButton * button )

此信號發射,當給定 button is clicked. A button is clicked when it is first pressed and then released, when its shortcut key is typed, or programmatically when QAbstractButton::click () 或 QAbstractButton::animateClick () 被調用。

注意: 信號 buttonClicked 在此類中是重載。要使用函數指針句法連接到此信號,必須在靜態鑄造中指定信號類型,如此範例所示:

connect(buttonGroup, static_cast<void(QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonClicked),
    [=](QAbstractButton *button){ /* ... */ });
					

另請參閱 checkedButton () 和 QAbstractButton::clicked ().

[signal] void QButtonGroup:: buttonClicked ( int id )

此信號被發射當按鈕具有給定 id 被點擊。

注意: 信號 buttonClicked 在此類中是重載。要使用函數指針句法連接到此信號,必須在靜態鑄造中指定信號類型,如此範例所示:

connect(buttonGroup, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
    [=](int id){ /* ... */ });
					

另請參閱 checkedButton () 和 QAbstractButton::clicked ().

[signal] void QButtonGroup:: buttonPressed ( QAbstractButton * button )

此信號發射,當給定 button 被按下。

注意: 信號 buttonPressed 在此類中是重載。要使用函數指針句法連接到此信號,必須在靜態鑄造中指定信號類型,如此範例所示:

connect(buttonGroup, static_cast<void(QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonPressed),
    [=](QAbstractButton *button){ /* ... */ });
					

該函數在 Qt 4.2 引入。

另請參閱 QAbstractButton::pressed ().

[signal] void QButtonGroup:: buttonPressed ( int id )

此信號被發射當按鈕具有給定 id 被按下。

注意: 信號 buttonPressed 在此類中是重載。要使用函數指針句法連接到此信號,必須在靜態鑄造中指定信號類型,如此範例所示:

connect(buttonGroup, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonPressed),
    [=](int id){ /* ... */ });
					

該函數在 Qt 4.2 引入。

另請參閱 QAbstractButton::pressed ().

[signal] void QButtonGroup:: buttonReleased ( QAbstractButton * button )

此信號發射,當給定 button 被釋放。

注意: 信號 buttonReleased 在此類中是重載。要使用函數指針句法連接到此信號,必須在靜態鑄造中指定信號類型,如此範例所示:

connect(buttonGroup, static_cast<void(QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonReleased),
    [=](QAbstractButton *button){ /* ... */ });
					

該函數在 Qt 4.2 引入。

另請參閱 QAbstractButton::released ().

[signal] void QButtonGroup:: buttonReleased ( int id )

此信號被發射當按鈕具有給定 id 被釋放。

注意: 信號 buttonReleased 在此類中是重載。要使用函數指針句法連接到此信號,必須在靜態鑄造中指定信號類型,如此範例所示:

connect(buttonGroup, static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonReleased),
    [=](int id){ /* ... */ });
					

該函數在 Qt 4.2 引入。

另請參閱 QAbstractButton::released ().

QList < QAbstractButton *> QButtonGroup:: buttons () const

Returns the list of this groups's buttons. This may be empty.

另請參閱 addButton () 和 removeButton ().

QAbstractButton * QButtonGroup:: checkedButton () const

返迴按鈕組的被復選按鈕,或 0 若沒有按鈕被復選。

另請參閱 buttonClicked ().

int QButtonGroup:: checkedId () const

返迴 ID 為 checkedButton (),或 -1 若沒有按鈕被復選。

該函數在 Qt 4.1 引入。

另請參閱 setId ().

int QButtonGroup:: id ( QAbstractButton * button ) const

返迴 ID 為指定 button ,或 -1 若不存在這種按鈕。

該函數在 Qt 4.1 引入。

另請參閱 setId ().

void QButtonGroup:: removeButton ( QAbstractButton * button )

移除給定 button 從按鈕組。

另請參閱 addButton () 和 buttons ().

void QButtonGroup:: setId ( QAbstractButton * button , int id )

設置 id 為指定 button 。注意, id can not be -1.

該函數在 Qt 4.1 引入。

另請參閱 id ().