QML使用MouseArea

1、普通使用

MouseArea {
    anchors.fill: parent
    hoverEnabled: true//为true才会触发进入信号
    onClicked: {
        
    }
    onEntered: {
        
    }
    onExited: {
        
    }
}

 

2、可拖曳

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
ApplicationWindow {
    visible: true
    width: 640
    height: 480
    Rectangle {
        width: 40
        height: 40
        color: "teal"
        MouseArea {
            anchors.fill: parent
            drag.target: parent
            drag.minimumX: 0
            drag.maximumX: 640-parent.width
            drag.axis: Drag.XAndYAxis
        }
    }
}

 

posted @ 2019-07-31 20:39  朱小勇  阅读(659)  评论(0编辑  收藏  举报