Qt QML在按下鼠标时动态转移鼠标所有权
我有一个应用程序,右侧有一个图像列表(使用 一个列表视图)和一个查看器(位于左侧)。用户可以将图像从列表拖动到查看器,并将图像保留在列表中(类似于列表预览,但具有拖放功能) 为此,当用户“按住”列表中的图像时,我会创建该图像的副本,并将其放在列表中图像的前面(我更改边框以便知道它是副本) 如果我随后释放并再次单击副本,我可以将副本移动到查看器中,并且一旦释放副本,我将销毁副本,如果将副本放在查看器区域中,则处理删除操作 除非我释放并单击副本,否则我无法执行此操作,因为当鼠标处于保留状态时,我无法将“鼠标所有权”从列表图像mousearea转移到副本图像mouseareaQt QML在按下鼠标时动态转移鼠标所有权,qt,drag-and-drop,qml,focus,mouseevent,Qt,Drag And Drop,Qml,Focus,Mouseevent,我有一个应用程序,右侧有一个图像列表(使用 一个列表视图)和一个查看器(位于左侧)。用户可以将图像从列表拖动到查看器,并将图像保留在列表中(类似于列表预览,但具有拖放功能) 为此,当用户“按住”列表中的图像时,我会创建该图像的副本,并将其放在列表中图像的前面(我更改边框以便知道它是副本) 如果我随后释放并再次单击副本,我可以将副本移动到查看器中,并且一旦释放副本,我将销毁副本,如果将副本放在查看器区域中,则处理删除操作 除非我释放并单击副本,否则我无法执行此操作,因为当鼠标处于保留状态时,我无法
有什么想法吗?提前谢谢 对于任何想找类似东西的人,我就是这样做的: 在代理上,我添加了鼠标区域:
MouseArea { // This is the mouse area on the original image-list
id: thumbnailDelegateMA
anchors { fill: parent }
cursorShape: containsMouse ? (drag.active ? Qt.ClosedHandCursor : Qt.PointingHandCursor) : Qt.ArrowCursor
property var copyThumbnail: undefined
drag.target: copyThumbnail ? copyThumbnail : null
onPressAndHold: {
if(!copyThumbnail){
copyThumbnail = createThumbnailCopy(imageID, parent)
parent = copyThumbnail
anchors.fill = copyThumbnail
}
}
onReleased:{
if(copyThumbnail){
parent = copyThumbnail.original
anchors.fill = copyThumbnail.original
copyThumbnail.destroy()
}
}
}
其中:
function createThumbnailCopy(uid, cparent){
var main_window = cparent.parent.parent;
var mapPos = mapFromItem(main_window, cparent.x, cparent.y);
var thumbnailCopy = thumbnailCopyComponent.createObject(
main_window,
{ "original": cparent,
"id": uid
"x": mapPos .x,
"y": mapPos .y
});
return thumbnailCopy;
}
以及:
Component{
id: thumbnailCopyComponent
Image {
id: thumbnailCopy
property string id;
property var original: undefined
Drag.hotSpot: Qt.point(width/2, 0)
Drag.active: true
fillMode: Image.PreserveAspectFit
source: "image://thumbnailProvider/" + id
}
}