QML-Button示例

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5

Window {
    width: 640
    height: 480
    color: "white"
    title: qsTr("My QML")
    visible: true

    //autoExclusive true按钮排它
    Button{
        id:btn1
        width: 50
        height: 50
        checkable: true
        x:0
        autoExclusive: true
    }
    Button{
        id:btn2
        width: 50
        height: 50
        checkable: true
        x:70
        autoExclusive: true
    }
    Button{
        id:btn3
        width: 50
        height: 50
        checkable: true
        x:140
        autoExclusive: true
    }


    Button{
        id:btn4
        width: 50
        height: 50
        y:100
        //点击不松开会连续触发三个信号
        autoRepeat: true
        //第一次触发到之后连续触发三个信号的间隔 单位毫秒
        autoRepeatDelay: 2000
        //连续触发三个信号的间隔
        autoRepeatInterval: 1000
        //点击变色 在深色点击变浅色 在浅色点击变深色
        checkable: true
        //摁下 true 松开或移除鼠标 false
        onDownChanged: {
            console.log("down",down,"pressed",pressed)
        }
        onClicked: {
            console.log("clicked")
        }
        onPressed: {
            console.log("pressed")
        }
        onReleased: {
            console.log("released")
        }
    }


    Button{
        id: btn5
        width: 200
        height: 50
        x: 100
        y: 100

        //icon
//        icon.source: "/test.jpg"
//        icon.color: "red"
        //Image
//        indicator: Image {
//            id: ind
//            source: "/test.jpg"
//        }
        //按钮文本
        text: "pressed"
        //点击不松开会连续触发三个信号
        autoRepeat: true
        //按钮背景
        background: Rectangle{
            anchors.fill: btn5
            //填充
            color: {
                if(btn5.pressed){
                    return "green"
                }
                else{
                    return "blue"
                }
            }
            //边框
            border.width: 5
            border.color: {
                if(btn5.pressed){
                    return "red"
                }
                else{
                    return "black"
                }
            }

        }

    }

}


  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值