Qt 为什么会有";onExited”一词;调用事件处理程序,而不是“引用”;onDropped“是吗?”;?

Qt 为什么会有";onExited”一词;调用事件处理程序,而不是“引用”;onDropped“是吗?”;?,qt,qml,Qt,Qml,我试图了解如何使用QML的拖放功能。因此,我对文档中的第一个示例进行了如下修改: import QtQuick 2.15 import QtQuick.Window 2.15 Window { width: 400 height: 400 visible: true Item { anchors.fill: parent DropArea { x: 100; y: 100; width: 100; he

我试图了解如何使用QML的
拖放功能。因此,我对文档中的第一个示例进行了如下修改:

import QtQuick 2.15
import QtQuick.Window 2.15

Window {
    width: 400
    height: 400
    visible: true

    Item {
        anchors.fill: parent

        DropArea {
            x: 100; y: 100; width: 100; height: 100

            onEntered: console.log("entered")
            onExited: console.log("exited")
            onPositionChanged: console.log("dragged to (" + drag.x + ", "
                                           + drag.y + ")")
            onDropped: console.log("dropped")

            Rectangle {
                anchors.fill: parent
                color: parent.containsDrag ? "green" : "yellow"
            }
        }

        Rectangle {
            x: 10; y: 10; width: 50; height: 50
            color: "red"

            Drag.active: dragArea.drag.active
            Drag.hotSpot.x: 25
            Drag.hotSpot.y: 25

            MouseArea {
                id: dragArea
                anchors.fill: parent
                drag.target: parent
            }
        }
    }
}
因此,当我将红色矩形拖动到拖放区域并将其拖放到该区域时,我希望
拖放的
将记录在控制台中。相反,我退出了

qml: entered
qml: dragged to (2, 1)
qml: dragged to (3, 2)
qml: dragged to (5, 3)
qml: dragged to (5, 4)
...
qml: dragged to (44, 39)
qml: dragged to (45, 40)
qml: dragged to (46, 40)
qml: exited <- Shouldn't this be 'dropped'
qml:已输入
qml:拖动到(2,1)
qml:拖动到(3,2)
qml:拖动到(5,3)
qml:拖动到(5,4)
...
qml:拖动到(44,39)
qml:拖动到(45,40)
qml:拖动到(46,40)

qml:对于我来说,qml中的拖放系统实在是太恶心了。您可能需要使用
Drag.dragType
。我记得,如果这不是自动的,你必须通过编程来启动和停止它。或者尝试解决方案,这应该会对你有所帮助。至于我,QML中的拖放系统令人恶心,我也有同样的感觉。谢谢你的提示和链接@福利比斯,真的很恶心。事实证明,虽然我能够移动矩形,但这根本不被认为是拖动(多亏了你,我现在更明白了。我可以请你写这封信作为答复,这样我就可以接受了。