QButtonGroup Class▲
-
Header: QButtonGroup
-
qmake: QT += widgets
-
Inherits: QObject
-
Group: QButtonGroup is part of organizers, geomanagement
Detailed Description▲
QButtonGroup provides an abstract container into which button widgets can be placed. It does not provide a visual representation of this container (see QGroupBox for a container widget), but instead manages the states of each of the buttons in the group.
An exclusive button group switches off all checkable (toggle) buttons except the one that has been clicked. By default, a button group is exclusive. The buttons in a button group are usually checkable QPushButtons, QCheckBoxes (normally for non-exclusive button groups), or QRadioButtons. 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 can be added to the group with addButton() and removed with removeButton(). If the group is exclusive, the currently checked button is available with checkedButton(). If a button is clicked, the buttonClicked() signal is emitted; for a checkable button in an exclusive group this means that the button has been checked. The list of buttons in the group is returned by buttons().
In addition, QButtonGroup can map between integers and buttons. You can assign an integer id to a button with setId(), and retrieve it with id(). The id of the currently checked button is available with checkedId(), and there is an overloaded signal buttonClicked() which emits the id of the button. The id -1 is reserved by QButtonGroup to mean "no such button". The purpose of the mapping mechanism is to simplify the representation of enum values in a user interface.
See Also▲
See also QGroupBox, QPushButton, QCheckBox, QRadioButton
Property Documentation▲
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.
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)
Member Function Documentation▲
[explicit] QButtonGroup::QButtonGroup(QObject *parent = nullptr)▲
Constructs a new, empty button group with the given parent.
See Also▲
See also addButton(), setExclusive()
[virtual] QButtonGroup::~QButtonGroup()▲
Destroys the button group.
void QButtonGroup::addButton(QAbstractButton *button, int id = -1)▲
Adds the given button to the button group. If id is -1, an id will be assigned to the button. Automatically assigned ids are guaranteed to be negative, starting with -2. If you are assigning your own ids, use positive values to avoid conflicts.
See Also▲
See also removeButton(), buttons()
[since 4.1] QAbstractButton *QButtonGroup::button(int id) const▲
This function was introduced in Qt 4.1.
void QButtonGroup::buttonClicked(QAbstractButton *button)▲
See Also▲
See also checkedButton(), QAbstractButton::clicked()
void QButtonGroup::buttonClicked(int id)▲
See Also▲
See also checkedButton(), QAbstractButton::clicked()
[since 4.2] void QButtonGroup::buttonPressed(QAbstractButton *button)▲
[since 4.2] void QButtonGroup::buttonPressed(int id)▲
[since 4.2] void QButtonGroup::buttonReleased(QAbstractButton *button)▲
[since 4.2] void QButtonGroup::buttonReleased(int id)▲
[since 5.2] void QButtonGroup::buttonToggled(QAbstractButton *button, bool checked)▲
[since 5.2] void QButtonGroup::buttonToggled(int id, bool checked)▲
QList<QAbstractButton *> QButtonGroup::buttons() const▲
See Also▲
See also addButton(), removeButton()
QAbstractButton *QButtonGroup::checkedButton() const▲
Returns the button group's checked button, or 0 if no buttons are checked.
See Also▲
See also buttonClicked()
[since 4.1] int QButtonGroup::checkedId() const▲
Returns the id of the checkedButton(), or -1 if no button is checked.
This function was introduced in Qt 4.1.
See Also▲
See also setId()
[since 4.1] int QButtonGroup::id(QAbstractButton *button) const▲
Returns the id for the specified button, or -1 if no such button exists.
This function was introduced in Qt 4.1.
See Also▲
See also setId()