为什么拖动后 onReleased 不启动

Why does not onReleased fire up after a drag

我有一个鼠标区域有这样的东西

onPressed: {
  cursorShape = Qt.ClosedHandCursor
  console.log("closed")
}

onReleased: {
  cursorShape = Qt.OpenHandCursor
  console.log("open")
}

cursorShape: Qt.OpenHandCursor

如果我在没有任何鼠标移动的情况下单击并释放,光标图标会按预期更改。但是,如果我在单击时移动鼠标,光标图标仍然是闭合的手。

这是为什么?

我刚刚使用 QML 中的以下代码检查了行为是否正确。

import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2

ApplicationWindow {
    id: mainwindow
    width: 640
    height: 480
    visible: true

    Flickable {
        width: 200; height: 200
        contentWidth: image.width
        contentHeight: image.height
        clip: true

        Image {
            id: image;
            source: "images/icon.png"

            MouseArea {
                anchors.fill: parent
                preventStealing: true

                onPressed: {
                  cursorShape = Qt.ClosedHandCursor
                  console.log("closed")
                }

                onReleased: {
                  cursorShape = Qt.OpenHandCursor
                  console.log("open")
                }

                cursorShape: Qt.OpenHandCursor
            }
        }
    }
}

preventStealing 设置为 true 会使 MouseArea 正常工作,并且 cursorShape 更改正常。但缺点(一个很大的缺点)是轻弹手势被 MouseArea 窃取,因此不会生成轻弹动作。

因此,我建议在用户交互结束时处理 onMovementEnded 以设置 cursorShape = Qt.OpenHandCursor

import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2

ApplicationWindow {
    id: mainwindow
    width: 640
    height: 480
    visible: true

    Flickable {
        width: 200; height: 200
        contentWidth: image.width
        contentHeight: image.height
        clip: true

        onMovementEnded: {
            mousearea.cursorShape = Qt.OpenHandCursor
            console.log("onMovementEnded")
        }

        Image {
            id: image;
            source: "images/icon.png"

            MouseArea {
                id: mousearea
                anchors.fill: parent

                onPressed: {
                    cursorShape = Qt.ClosedHandCursor
                    console.log("closed")
                }

                onReleased: {
                    cursorShape = Qt.OpenHandCursor
                    console.log("open")
                }

                cursorShape: Qt.OpenHandCursor
            }
        }
    }
}