QML学习06Button

QMLx学习06Button

  • 1、Button
    • [1.1 状态改变(checkable)](#1.1 状态改变(checkable))
    • [1.2 排斥性(autoExclusive)](#1.2 排斥性(autoExclusive))
    • [1.3 重复触发(autoRepeat)、第一次触发延时时间(autoRepeatDelay)、相互之间触发的时间间隔(autoRepeatInterval)](#1.3 重复触发(autoRepeat)、第一次触发延时时间(autoRepeatDelay)、相互之间触发的时间间隔(autoRepeatInterval))
    • [1.4 鼠标按下(onDownChanged)](#1.4 鼠标按下(onDownChanged))
    • [1.5 改变按钮背景颜色和边框颜色(background: Rectangle、border.color)](#1.5 改变按钮背景颜色和边框颜色(background: Rectangle、border.color))
  • 2、总结

1、Button

1.1 状态改变(checkable)

cpp 复制代码
    Button {
        id:btn
        width:50
        height:50
        //checkable: true         //按钮被选中状态
        checkable: false

        onCheckableChanged: {
            console.log("changed",checkable)
        }

        onClicked: {
            btn.checkable = !btn.checkable      //可以强制改变checkable状态
        }

1.2 排斥性(autoExclusive)

cpp 复制代码
Button {
    id:btn
    width: 50
    height: 50
    autoExclusive: true   //排斥性,只有一个按钮能被checkable
    checkable: true
}

Button {
    id:btn1
    width: 50
    height: 50
    x:60
    autoExclusive: true
    checkable: true
}

Button {
    id:btn2
    width: 50
    height: 50
    x:120
    autoExclusive: true
    checkable: true
}

1.3 重复触发(autoRepeat)、第一次触发延时时间(autoRepeatDelay)、相互之间触发的时间间隔(autoRepeatInterval)

cpp 复制代码
Button{
    id:btn
    width: 50
    height: 50
    autoRepeat: true            //重复触发
    autoRepeatDelay: 2000       //第一次触发延时时间
    autoRepeatInterval: 1000    //相互之间触发的时间间隔

    onClicked: {
        console.log("clicked")
    }

    onPressed: {
        console.log("pressed")
    }

    onReleased: {
        console.log("released");
    }
}

1.4 鼠标按下(onDownChanged)

cpp 复制代码
Button{
    id:btn
    width: 50
    height: 50
    autoRepeat: true            //重复触发
    autoRepeatDelay: 2000       //第一次触发延时时间
    autoRepeatInterval: 1000    //相互之间触发的时间间隔
    checkable: true

    onDownChanged: {
        console.log("down:",down,"pressed",pressed)         //鼠标按下
    }

}

1.5 改变按钮背景颜色和边框颜色(background: Rectangle、border.color)

cpp 复制代码
Button{
    id:btn
    width: 50
    height: 50
    autoRepeat: true
    background: Rectangle{
        anchors.fill: btn
        color: {
            if(btn.pressed){
                return "green"
            }
            else{
                return "blue"
            }
        }

        border.width: 5
        border.color: {
            if(btn.pressed){
                return "red"
            }
            else{
                return "black"
            }
        }
    }
}

2、总结

|------------------------------------------------------------------------------------------------|
| 以上就是Button的一些基础知识了,浏览过程中,如若发现错误,欢迎大家指正,有问题的欢迎评论区留言或者私信。最后,如果大家觉得有所帮助,可以点一下赞,谢谢大家!祝大家天天开心,顺遂无虞! |

相关推荐
润 下3 分钟前
C语言——深入解析C语言指针:从基础到实践从入门到精通(二)
c语言·开发语言·经验分享·笔记·学习·程序人生
知识分享小能手38 分钟前
微信小程序入门学习教程,从入门到精通,电影之家小程序项目知识点详解 (17)
前端·javascript·学习·微信小程序·小程序·前端框架·vue
Dever41 分钟前
记一次 CORS 深水坑:开启 withCredentials 后Response headers 只剩 content-type
前端·javascript
风和先行1 小时前
Android Vibrator学习记录
学习
Hilaku1 小时前
为什么我开始减少逛技术社区,而是去读非技术的书?
前端·javascript·面试
应用市场1 小时前
Qt插件机制实现动态组件加载详解
开发语言·qt
猪哥帅过吴彦祖1 小时前
第 8 篇:更广阔的世界 - 加载 3D 模型
前端·javascript·webgl
Asort1 小时前
JavaScript设计模式(十二)——代理模式 (Proxy)
前端·javascript·设计模式
三三木木七1 小时前
AI超级智能体学习笔记
笔记·学习
tangdou3690986551 小时前
可怕!我的Nodejs系统因为日志打印了Error 对象就崩溃了😱 Node.js System Crashed Because of Logging
前端·javascript·后端