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