QButtonGroup Class
The QButtonGroup class provides a container to organize groups of button widgets. 更多...
头文件: | #include <QButtonGroup> |
qmake: | QT += widgets |
基类: | QObject |
属性
- exclusive : bool
- 1 个属性继承自 QObject
公有函数
QButtonGroup(QObject *parent = Q_NULLPTR) | |
~QButtonGroup() | |
void | addButton(QAbstractButton *button, int id = -1) |
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) |
- 32 个公有函数继承自 QObject
信号
void | buttonClicked(QAbstractButton *button) |
void | buttonClicked(int id) |
void | buttonPressed(QAbstractButton *button) |
void | buttonPressed(int id) |
void | buttonReleased(QAbstractButton *button) |
void | buttonReleased(int id) |
void | buttonToggled(QAbstractButton *button, bool checked) |
void | buttonToggled(int id, bool checked) |
- 2 个信号继承自 QObject
其他继承的成员
- 1 个公有槽函数继承自 QObject
- 1 个公有变量继承自 QObject
- 10 个静态公有成员继承自 QObject
- 9 个受保护的函数继承自 QObject
- 2 个受保护的变量继承自 QObject
详细描述
The QButtonGroup 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 (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.
参见 QGroupBox, QPushButton, QCheckBox, and 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.
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
.
访问函数:
bool | exclusive() const |
void | setExclusive(bool) |
成员函数
QButtonGroup::QButtonGroup(QObject *parent = Q_NULLPTR)
Constructs a new, empty button group with the given parent.
参见 addButton() and setExclusive().
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.
参见 removeButton() and buttons().
QAbstractButton *QButtonGroup::button(int id) const
Returns the button with the specified id, 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 given button is clicked. A button is clicked when it is first pressed and then released, when its shortcut key is typed, or when QAbstractButton::click() or QAbstractButton::animateClick() is programmatically called.
Note: Signal buttonClicked 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){ /* ... */ });
参见 checkedButton() and QAbstractButton::clicked().
[signal]
void QButtonGroup::buttonClicked(int id)
This signal is emitted when a button with the given id is clicked.
Note: Signal buttonClicked 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){ /* ... */ });
参见 checkedButton() and QAbstractButton::clicked().
[signal]
void QButtonGroup::buttonPressed(QAbstractButton *button)
This signal is emitted when the given button is pressed down.
Note: Signal buttonPressed 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.
参见 QAbstractButton::pressed().
[signal]
void QButtonGroup::buttonPressed(int id)
This signal is emitted when a button with the given id is pressed down.
Note: Signal buttonPressed 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.
参见 QAbstractButton::pressed().
[signal]
void QButtonGroup::buttonReleased(QAbstractButton *button)
This signal is emitted when the given button is released.
Note: Signal buttonReleased 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.
参见 QAbstractButton::released().
[signal]
void QButtonGroup::buttonReleased(int id)
This signal is emitted when a button with the given id is released.
Note: Signal buttonReleased 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.
参见 QAbstractButton::released().
[signal]
void QButtonGroup::buttonToggled(QAbstractButton *button, bool checked)
This signal is emitted when the given button is toggled. checked is true if the button is checked, or false if the button is unchecked.
Note: Signal buttonToggled 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 *, bool)>(&QButtonGroup::buttonToggled), [=](QAbstractButton *button, bool checked){ /* ... */ });
This function was introduced in Qt 5.2.
参见 QAbstractButton::toggled().
[signal]
void QButtonGroup::buttonToggled(int id, bool checked)
This signal is emitted when a button with the given id is toggled. checked is true if the button is checked, or false if the button is unchecked.
Note: Signal buttonToggled 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, bool)>(&QButtonGroup::buttonToggled), [=](int id, bool checked){ /* ... */ });
This function was introduced in Qt 5.2.
参见 QAbstractButton::toggled().
QList<QAbstractButton *> QButtonGroup::buttons() const
Returns the button group's list of buttons. This may be empty.
参见 addButton() and removeButton().
QAbstractButton *QButtonGroup::checkedButton() const
Returns the button group's checked button, or 0 if no buttons are checked.
参见 buttonClicked().
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.
参见 setId().
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.
参见 setId().
void QButtonGroup::removeButton(QAbstractButton *button)
Removes the given button from the button group.
void QButtonGroup::setId(QAbstractButton *button, int id)
Sets the id for the specified button. Note that id cannot be -1.
This function was introduced in Qt 4.1.
参见 id().