ButtonGroup QML Type
상호 배타적인 확인 가능 버튼 그룹. 더 보기...
Import Statement: | import QtQuick.Controls |
Inherits: |
속성
- buttons : list<AbstractButton>
- checkState : enumeration
(since QtQuick.Controls 2.4 (Qt 5.11))
- checkedButton : AbstractButton
- exclusive : bool
(since QtQuick.Controls 2.3 (Qt 5.10))
첨부 속성
- group : ButtonGroup
신호
- clicked(AbstractButton button)
(since QtQuick.Controls 2.1 (Qt 5.8))
방법
- void addButton(AbstractButton button)
- void removeButton(AbstractButton button)
상세 설명
버튼 그룹은 시각적이지 않은 상호 배타적인 버튼 그룹입니다. 한 번에 하나의 옵션만 선택할 수 있는 RadioButton 와 같은 컨트롤에 사용됩니다.
ButtonGroup을 사용하는 가장 간단한 방법은 버튼 목록을 할당하는 것입니다. 예를 들어 포지셔너의 자식 목록이나 상호 배타적인 버튼 그룹을 관리하는 레이아웃을 지정할 수 있습니다.
ButtonGroup { buttons: column.children } Column { id: column RadioButton { checked: true text: qsTr("DAB") } RadioButton { text: qsTr("FM") } RadioButton { text: qsTr("AM") } }
상호 배타적인 버튼이 항상 동일한 상위 항목을 공유하는 것은 아니거나 상위 레이아웃에 버튼 그룹에 포함되지 않아야 하는 항목이 포함될 수 있습니다. 이러한 경우 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 } }
또 다른 옵션은 하위 목록을 필터링하는 것입니다. 이 방법은 리피터를 사용하여 채우는 경우 특히 유용합니다. 리피터도 상위 레이아웃의 하위 레이아웃이 되기 때문입니다:
ButtonGroup { buttons: column.children.filter((child) => child !== repeater) } Column { id: column Repeater { id: repeater model: [ qsTr("DAB"), qsTr("AM"), qsTr("FM") ] RadioButton { required property string modelData text: modelData } } }
보다 고급 사용 사례는 addButton()
및 removeButton()
메서드를 사용하여 처리할 수 있습니다.
RadioButton 및 버튼 컨트롤도참조하세요 .
속성 문서
buttons : list<AbstractButton> |
이 속성은 버튼 목록을 보유합니다.
ButtonGroup { buttons: column.children } Column { id: column RadioButton { checked: true text: qsTr("Option A") } RadioButton { text: qsTr("Option B") } }
group 를참조하세요 .
checkState : enumeration |
이 속성은 버튼 그룹의 결합된 확인 상태를 보유합니다.
사용 가능한 상태
Constant | 설명 |
---|---|
Qt.Unchecked | 선택된 버튼이 없습니다. |
Qt.PartiallyChecked | 일부 버튼이 선택됨. |
Qt.Checked | 모든 버튼이 선택되어 있습니다. |
비독점 버튼 그룹의 확인 상태를 Qt.Unchecked
또는 Qt.Checked
으로 설정하면 그룹의 모든 버튼이 각각 선택 해제되거나 선택 취소됩니다. Qt.PartiallyChecked
은 무시됩니다.
독점 버튼 그룹의 체크 상태를 Qt.Unchecked
로 설정하면 checkedButton 의 체크가 해제됩니다. Qt.Checked
및 Qt.PartiallyChecked
은 무시됩니다.
이 프로퍼티는 QtQuick.Controls 2.4(Qt 5.11)에 도입되었습니다.
checkedButton : AbstractButton |
이 속성은 현재 선택된 버튼이 독점 그룹에 속해 있거나, 그룹이 없거나 비독점인 경우 null
을 보유합니다.
기본적으로 이 속성은 독점 버튼 그룹에 추가된 첫 번째 체크된 버튼입니다.
exclusive도 참조하세요 .
exclusive : bool |
이 속성은 버튼 그룹이 독점적인지 여부를 보유합니다. 기본값은 true
입니다.
이 속성이 true
인 경우 그룹에서 한 번에 하나의 버튼만 확인할 수 있습니다. 사용자는 아무 버튼이나 클릭하여 확인할 수 있으며, 해당 버튼은 그룹에서 기존 버튼을 체크된 버튼으로 대체합니다.
독점 그룹에서는 사용자가 현재 선택된 버튼을 클릭하여 선택을 취소할 수 없으며, 그룹의 다른 버튼을 클릭하여 해당 그룹에 대한 새 선택 버튼을 설정해야 합니다.
비독점 그룹에서는 버튼을 선택하거나 선택 취소해도 그룹 내 다른 버튼에는 영향을 미치지 않습니다. 또한 checkedButton 속성의 값은 null
입니다.
이 프로퍼티는 QtQuick.Controls 2.3(Qt 5.10)에 도입되었습니다.
첨부 속성 문서
ButtonGroup.group : ButtonGroup |
이 속성은 버튼을 버튼 그룹에 첨부합니다.
ButtonGroup { id: group } RadioButton { checked: true text: qsTr("Option A") ButtonGroup.group: group } RadioButton { text: qsTr("Option B") ButtonGroup.group: group }
buttons 를참조하십시오 .
신호 문서
|
이 신호는 그룹에 있는 button 을 클릭했을 때 발생합니다.
이 신호는 같은 그룹의 모든 버튼에 대해 공통 신호 처리기를 구현할 때 편리합니다.
ButtonGroup { buttons: column.children onClicked: console.log("clicked:", button.text) } Column { id: column Button { text: "First" } Button { text: "Second" } Button { text: "Third" } }
참고: 해당 핸들러는 onClicked
입니다.
이 신호는 QtQuick.Controls 2.1(Qt 5.8)에서 도입되었습니다.
AbstractButton::clicked()도 참조하십시오 .
메서드 문서
void addButton(AbstractButton button) |
void removeButton(AbstractButton button) |
© 2025 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 the GNU 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.