qt qml 自定义图片按钮源码


上方是效果图

 

import QtQuick 2.0

Item {
    id: root
    property url imgSource: ""
    property url pressedImgSource: ""
    signal clicked()
    width: 50
    height: 50
    Image{
        id:img
        source: imgSource
        anchors.fill: parent
    }
    MouseArea{
        id: mouseArea
        anchors.fill: parent
        onPressed: {
            img.source = pressedImgSource
            root.clicked()
        }
        onReleased: {
            img.source = imgSource
        }
    }
}