qml禁用引出的双向绑定问题

文章介绍

demo.qml

效果

在这里插入图片描述

代码

import QtQuick 2.15
import QtQuick.Controls 2.15

ApplicationWindow {
    visible: true
    width: 300
    height: 200
    title: "切换开关控制示例"

    // 主开关,用于控制其他两个开关的禁用状态
    Switch {
        id: mainSwitch
        text: "启用/禁用其他开关"
        anchors.top: parent.top
        anchors.horizontalCenter: parent.horizontalCenter
        checked: true
    }

    // 第一个开关
    Switch {
        id: switch1
        text: "开关 1"
        anchors.top: mainSwitch.bottom
        anchors.topMargin: 20
        anchors.horizontalCenter: parent.horizontalCenter
        enabled: mainSwitch.checked  // 根据主开关的状态禁用或启用
    }

    // 第二个开关
    Switch {
        id: switch2
        text: "开关 2"
        anchors.top: switch1.bottom
        anchors.topMargin: 20
        anchors.horizontalCenter: parent.horizontalCenter
        enabled: mainSwitch.checked  // 根据主开关的状态禁用或启用
    }
}

实际项目需求

面临问题

在这里插入图片描述

解决办法

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值