
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQButtonGroup class provides a container to organize groups of button widgets.More...
| Header: | #include <QButtonGroup> |
| Inherits: | 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) |
TheQButtonGroup class provides a container to organize groups of button widgets.
QButtonGroup provides an abstract container into which button widgets can be placed. It does not provide a visual representation of this container (seeQGroupBox for a container widget), but instead manages the states of each of the buttons in the group.
Anexclusive 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 checkableQPushButton's,QCheckBoxes (normally for non-exclusive button groups), orQRadioButtons. If you create an exclusive button group, you should ensure that one of the buttons in the group is initially checked; otherwise, the group will initially be in a state where no buttons are checked.
A button is added to the group withaddButton(). It can be removed from the group withremoveButton(). If the group is exclusive, the currently checked button is available ascheckedButton(). If a button is clicked thebuttonClicked() 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 bybuttons().
In addition,QButtonGroup can map between integers and buttons. You can assign an integer id to a button withsetId(), and retrieve it withid(). The id of the currently checked button is available withcheckedId(), and there is an overloaded signalbuttonClicked() which emits the id of the button. The id-1 is reserved byQButtonGroup to mean "no such button". The purpose of the mapping mechanism is to simplify the representation of enum values in a user interface.
See alsoQGroupBox,QPushButton,QCheckBox, andQRadioButton.
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.
In an exclusive group, the user cannot uncheck the currently checked button by clicking on it; instead, another button in the group must be clicked to set the new checked button for that group.
By default, this property is true.
Access functions:
| bool | exclusive() const |
| void | setExclusive(bool) |
Constructs a new, empty button group with the givenparent.
See alsoaddButton() andsetExclusive().
Destroys the button group.
Adds the givenbutton to the end of the group's internal list of buttons. An id will be assigned to the button by thisQButtonGroup. 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.
See alsoremoveButton() andbuttons().
Adds the givenbutton to the button group, with the givenid. It is recommended to assign only positive ids.
See alsoremoveButton() andbuttons().
Returns the button with the specifiedid, or 0 if no such button exists.
This function was introduced in Qt 4.1.
[signal]void QButtonGroup::buttonClicked(QAbstractButton * button)This signal is emitted when the givenbutton is clicked. A button is clicked when it is first pressed and then released, when its shortcut key is typed, or programmatically whenQAbstractButton::click() orQAbstractButton::animateClick() is called.
Note:SignalbuttonClicked is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(buttonGroup,static_cast<void(QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonClicked),[=](QAbstractButton*button){/* ... */ });
See alsocheckedButton() andQAbstractButton::clicked().
[signal]void QButtonGroup::buttonClicked(int id)This signal is emitted when a button with the givenid is clicked.
Note:SignalbuttonClicked is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(buttonGroup,static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),[=](int id){/* ... */ });
See alsocheckedButton() andQAbstractButton::clicked().
[signal]void QButtonGroup::buttonPressed(QAbstractButton * button)This signal is emitted when the givenbutton is pressed down.
Note:SignalbuttonPressed is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(buttonGroup,static_cast<void(QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonPressed),[=](QAbstractButton*button){/* ... */ });
This function was introduced in Qt 4.2.
See alsoQAbstractButton::pressed().
[signal]void QButtonGroup::buttonPressed(int id)This signal is emitted when a button with the givenid is pressed down.
Note:SignalbuttonPressed is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(buttonGroup,static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonPressed),[=](int id){/* ... */ });
This function was introduced in Qt 4.2.
See alsoQAbstractButton::pressed().
[signal]void QButtonGroup::buttonReleased(QAbstractButton * button)This signal is emitted when the givenbutton is released.
Note:SignalbuttonReleased is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(buttonGroup,static_cast<void(QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonReleased),[=](QAbstractButton*button){/* ... */ });
This function was introduced in Qt 4.2.
See alsoQAbstractButton::released().
[signal]void QButtonGroup::buttonReleased(int id)This signal is emitted when a button with the givenid is released.
Note:SignalbuttonReleased is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(buttonGroup,static_cast<void(QButtonGroup::*)(int)>(&QButtonGroup::buttonReleased),[=](int id){/* ... */ });
This function was introduced in Qt 4.2.
See alsoQAbstractButton::released().
Returns the list of this groups's buttons. This may be empty.
See alsoaddButton() andremoveButton().
Returns the button group's checked button, or 0 if no buttons are checked.
See alsobuttonClicked().
Returns the id of thecheckedButton(), or -1 if no button is checked.
This function was introduced in Qt 4.1.
See alsosetId().
Returns the id for the specifiedbutton, or -1 if no such button exists.
This function was introduced in Qt 4.1.
See alsosetId().
Removes the givenbutton from the button group.
See alsoaddButton() andbuttons().
Sets theid for the specifiedbutton. Note thatid can not be -1.
This function was introduced in Qt 4.1.
See alsoid().
© 2016 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 theGNU 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.