一个QML图标按钮控件样式

这个样式在当前项目已经用不到了,删了免得占空间,随便记录一下代码

封装后食用效果更佳:

import QtQuick 2.0

Image {
    id: button1
    // 按钮图标
    property string icon_source: ""
    // 图标下方文字
    property string bottom_text: ""
    // 文字字体属性
    property string font_family: "SinSun"
    property bool font_bold: false
    property real font_pointSize: 9
    // 按钮尺寸
    property real button_width: 64
    property real button_heigth: 48

    source: icon_source

    // 定义信号
    signal clicked

    width: button_width
    height: button_heigth

    // 被点击时按钮变灰
    Rectangle{
        id:shade
        anchors.fill: parent
        color: "black"
        // 不透明度  0透明 1不透明
        opacity: 0
    }
    // 鼠标区域
    MouseArea{
        id:mouse_area
        anchors.fill: parent
        enabled: (button1.visible && button1.enabled)
        onClicked: {
            // 触发 button1 的 clicked 信号
            button1.clicked();
        }
    }
    // 按钮下方文字
    Text {
        id: button_bottom_text
        text: qsTr(bottom_text)
        anchors.top: button1.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        // 字体 、 明显 、 字号
        font.family: font_family
        font.bold: font_bold
        font.pointSize: font_pointSize
    }
    // 状态切换,如果这行报错就注释掉
    state: State{
        name:"pressed"
        // 条件判断,被按压时触发
        when: (mouse_area.pressed === true)
        PropertyChanges {
            // 按钮变灰
            target: shade
            opacity:0.4
        }
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值