Qt笔记-qml-button

来源:互联网 发布:怎么卸载还原软件 编辑:程序博客网 时间:2024/05/29 09:53

qml 自定义按钮 pushButton

import QtQuick 2.0Rectangle {    id: sysbtn    signal clicked    property string btnImageCurrent: "qrc:/image/ButtonNormol.png"    property string btnImageDisable: "qrc:/image/ButtonDisabled.png"    property string btnImageNormol:  "qrc:/image/ButtonNormol.png"    property string btnImagePressed: "qrc:/image/ButtonPressed.png"    property string text: "hello world"    width: 156;//btnImage.width    height: 67;//btnImage.height    color:"#00000000"    state:"normal"    MouseArea{        hoverEnabled: true;        anchors.fill: parent;        onPressed:        {            if ( sysbtn.state == "normal" )               sysbtn.state = "pressed"        }        onReleased:        {            if ( sysbtn.state != "disable" )            {                sysbtn.state = "normal"                sysbtn.clicked()            }        }    }    Image {        id: btnImage        source: btnImageCurrent        anchors.horizontalCenter: parent.horizontalCenter        anchors.verticalCenter: parent.verticalCenter    }    Text {        id: m_text        color: "#ffffff"        font.pointSize: 14        font.family: "微软雅黑"        text: sysbtn.text        anchors.horizontalCenter: parent.horizontalCenter        anchors.verticalCenter: parent.verticalCenter    }    states: [        State {            name: "normal"            PropertyChanges {                target: sysbtn                btnImageCurrent: btnImageNormol            }        },        State {            name: "pressed"            PropertyChanges {                target: sysbtn                btnImageCurrent: btnImagePressed            }        },        State {            name: "disable"            PropertyChanges {                target: sysbtn                btnImageCurrent: btnImageDisable            }        }    ]}
原创粉丝点击