FluRadioButtons 组件支持 disabled、manuallyDisabled选项

disabled: true // 禁用所有FluRadioButton子组件
        manuallyDisabled: true // 是否指定每个FluRadioButton上的disabled选项
This commit is contained in:
gaoxiangyang 2024-05-08 21:10:00 +08:00
parent c36515f19c
commit 9aa6615189
3 changed files with 64 additions and 4 deletions

View File

@ -22,18 +22,37 @@ FluScrollablePage{
FluGroupBox {
title: qsTr("RadioButton Group")
Layout.fillWidth: true
Layout.preferredHeight: 150
Layout.topMargin: 20
FluRadioButtons {
anchors{
verticalCenter: parent.verticalCenter
left: parent.left
}
spacing: 10
disabled: radio_button_switch.checked
FluRadioButton { text: qsTr("E-mail") }
FluRadioButton { text: qsTr("Calendar") }
FluRadioButton { text: qsTr("Contacts") }
}
FluToggleSwitch{
id: radio_button_switch
anchors{
right: parent.right
verticalCenter: parent.verticalCenter
}
text: qsTr("Disabled")
}
}
CodeExpander{
Layout.fillWidth: true
Layout.topMargin: 4
code:'FluGroupBox {
code:`
FluGroupBox {
title: qsTr("CheckBox Group")
ColumnLayout {
spacing: 10
@ -42,7 +61,20 @@ FluScrollablePage{
FluCheckBox { text: qsTr("Calendar") }
FluCheckBox { text: qsTr("Contacts") }
}
}'
}
FluGroupBox {
title: qsTr("RadioButton Group")
FluRadioButtons {
spacing: 10
disabled: true // FluRadioButton
manuallyDisabled: true // FluRadioButtondisabled
FluRadioButton { text: qsTr("E-mail") }
FluRadioButton { text: qsTr("Calendar") }
FluRadioButton { text: qsTr("Contacts") }
}
}
`
}
}

View File

@ -6,6 +6,8 @@ import FluentUI 1.0
ColumnLayout {
default property alias buttons: control.data
property int currentIndex : -1
property bool disabled: false
property bool manuallyDisabled: false
id:control
onCurrentIndexChanged: {
for(var i = 0;i<buttons.length;i++){
@ -16,6 +18,12 @@ ColumnLayout {
button.checked = true
}
}
onDisabledChanged: {
refreshButtonStatus()
}
onManuallyDisabledChanged: {
refreshButtonStatus()
}
Component.onCompleted: {
for(var i = 0;i<buttons.length;i++){
buttons[i].clickListener = function(){
@ -27,6 +35,12 @@ ColumnLayout {
}
}
}
currentIndex = 0
refreshButtonStatus()
}
function refreshButtonStatus() {
for(var i = 0;i<buttons.length;i++){
if(!manuallyDisabled) buttons[i].enabled = !disabled
}
}
}

View File

@ -7,6 +7,8 @@ import FluentUI
ColumnLayout {
default property alias buttons: control.data
property int currentIndex : -1
property bool disabled: false
property bool manuallyDisabled: false
id:control
onCurrentIndexChanged: {
for(var i = 0;i<buttons.length;i++){
@ -17,6 +19,12 @@ ColumnLayout {
button.checked = true
}
}
onDisabledChanged: {
refreshButtonStatus()
}
onManuallyDisabledChanged: {
refreshButtonStatus()
}
Component.onCompleted: {
for(var i = 0;i<buttons.length;i++){
buttons[i].clickListener = function(){
@ -28,6 +36,12 @@ ColumnLayout {
}
}
}
currentIndex = 0
refreshButtonStatus()
}
function refreshButtonStatus() {
for(var i = 0;i<buttons.length;i++){
if(!manuallyDisabled) buttons[i].enabled = !disabled
}
}
}