Mutually-exclusive group of checkable buttons. 更多...
| import 語句: | import QtQuick.Controls 2.5 |
| Since: | Qt 5.7 |
| 繼承: | QtObject |
ButtonGroup is a non-visual, mutually exclusive group of buttons. It is used with controls such as RadioButton , where only one of the options can be selected at a time.
The most straight-forward way to use ButtonGroup is to assign a list of buttons. For example, the list of children of a positioner 或 layout that manages a group of mutually exclusive buttons.
ButtonGroup {
buttons: column.children
}
Column {
id: column
RadioButton {
checked: true
text: qsTr("DAB")
}
RadioButton {
text: qsTr("FM")
}
RadioButton {
text: qsTr("AM")
}
}
Mutually exclusive buttons do not always share the same parent item, or the parent layout may sometimes contain items that should not be included in the button group. Such cases are best handled using the group 附加特性。
ButtonGroup { id: radioGroup }
Column {
Label {
text: qsTr("Radio:")
}
RadioButton {
checked: true
text: qsTr("DAB")
ButtonGroup.group: radioGroup
}
RadioButton {
text: qsTr("FM")
ButtonGroup.group: radioGroup
}
RadioButton {
text: qsTr("AM")
ButtonGroup.group: radioGroup
}
}
More advanced use cases can be handled using the
addButton()
and
removeButton()
方法。
另請參閱 RadioButton and 按鈕控件 .
|
[default] buttons : list < AbstractButton > |
This property holds the list of buttons.
ButtonGroup {
buttons: column.children
}
Column {
id: column
RadioButton {
checked: true
text: qsTr("Option A")
}
RadioButton {
text: qsTr("Option B")
}
}
另請參閱 group .
|
checkState : enumeration |
This property holds the combined check state of the button group.
Available states:
| 常量 | 描述 |
|---|---|
Qt.Unchecked
|
None of the buttons are checked. |
Qt.PartiallyChecked
|
Some of the buttons are checked. |
Qt.Checked
|
All of the buttons are checked. |
Setting the check state of a non-exclusive button group to
Qt.Unchecked
or
Qt.Checked
unchecks or checks all buttons in the group, respectively.
Qt.PartiallyChecked
被忽略。
Setting the check state of an exclusive button group to
Qt.Unchecked
unchecks the
checkedButton
.
Qt.Checked
and
Qt.PartiallyChecked
被忽略。
This property was introduced in QtQuick.Controls 2.4 (Qt 5.11).
|
checkedButton : AbstractButton |
This property holds the currently selected button in an exclusive group, or
null
if there is none or the group is non-exclusive.
By default, it is the first checked button added to an exclusive button group.
另請參閱 exclusive .
|
exclusive : bool |
This property holds whether the button group is exclusive. The default value is
true
.
若此特性為
true
,則在任何給定時間隻能復選組中一個按鈕。用戶可以點擊任意按鈕以復選它,且該按鈕將替換組中的現有被復選按鈕。
在獨占組中,用戶無法通過點擊目前被復選的按鈕來取消復選;相反,必須點擊組中的另一按鈕來為該組設置新的被復選按鈕。
In a non-exclusive group, checking and unchecking buttons does not affect the other buttons in the group. Furthermore, the value of the
checkedButton
特性為
null
.
該特性在 QtQuick.Controls 2.3 (Qt 5.10) 引入。
|
ButtonGroup.group : ButtonGroup |
This property attaches a button to a button group.
ButtonGroup { id: group }
RadioButton {
checked: true
text: qsTr("Option A")
ButtonGroup.group: group
}
RadioButton {
text: qsTr("Option B")
ButtonGroup.group: group
}
另請參閱 buttons .
|
clicked ( AbstractButton button ) |
This signal is emitted when a button in the group has been clicked.
This signal is convenient for implementing a common signal handler for all buttons in the same group.
ButtonGroup {
buttons: column.children
onClicked: console.log("clicked:", button.text)
}
Column {
id: column
Button { text: "First" }
Button { text: "Second" }
Button { text: "Third" }
}
該信號在 QtQuick.Controls 2.1 (Qt 5.8) 引入。
另請參閱 AbstractButton::clicked() .
|
void addButton ( AbstractButton button ) |
添加 button to the button group.
注意: Manually adding objects to a button group is typically unnecessary. The buttons 特性和 group attached property provide a convenient and declarative syntax.
|
void removeButton ( AbstractButton button ) |
Removes a button 從按鈕組。
注意: Manually removing objects from a button group is typically unnecessary. The buttons 特性和 group attached property provide a convenient and declarative syntax.