fix(qml):解决拖拽后位置出现偏移、鼠标附着图片不居中的问题

This commit is contained in:
qiqi49 2024-02-26 14:24:30 +08:00
parent f46521509b
commit e41f971254
2 changed files with 22 additions and 17 deletions

View File

@ -59,8 +59,17 @@ AppListView {
focus: true
width: appListView.view ? appListView.view.width : 0
height: appListView.itemHeight
anchors.centerIn: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
drag.target: appItemBase
drag.target: appItem
Drag.hotSpot.x: 48 / 2
Drag.hotSpot.y: 48 / 2
Drag.supportedActions: Qt.CopyAction
Drag.dragType: Drag.Automatic
Drag.active: appItem.drag.active
Drag.mimeData: {"id": id, "favorite": favorite}
onClicked: {
if (mouse.button === Qt.RightButton) {
appListView.model.openMenu(index, MenuInfo.AppList);
@ -71,13 +80,13 @@ AppListView {
return;
}
}
onPressed: parent.grabImage();
onPressed: grabImage();
}
function grabImage() {
var icon = mouseGrabImage.createObject(appItemBase, { width: 48, height: 48, source: model.icon})
var icon = mouseGrabImage.createObject(appItem, {width: 48, height: 48, source: model.icon})
icon.grabToImage(function(result) {
appItemBase.Drag.imageSource = result.url
appItem.Drag.imageSource = result.url
return result;
});
icon.opacity = 0;
@ -88,10 +97,6 @@ AppListView {
UkuiItems.Icon { }
}
Drag.supportedActions: Qt.CopyAction
Drag.dragType: Drag.Automatic
Drag.active: appItem.drag.active
Drag.mimeData: {"id": id, "favorite": favorite}
Keys.onPressed: {
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {

View File

@ -98,17 +98,17 @@ ListView {
}
}
drag.target: parent
onPressed: parent.grabToImage(function(result) {
parent.Drag.imageSource = result.url
drag.target: appItem
onPressed: grabToImage(function(result) {
Drag.imageSource = result.url
})
}
Drag.supportedActions: Qt.CopyAction
Drag.dragType: Drag.Automatic
Drag.active: appItem.drag.active
Drag.hotSpot.x: width / 2
Drag.hotSpot.y: height / 2
Drag.mimeData: {"id": model.id, "favorite": model.favorite > 0}
}
//
Loader {