Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.4.2, 6.5
-
None
Description
In this example I have a DragHandler which will start a drag anywhere inside the window. The item that is being dragged is created on the fly when the drag starts.
That works, but the hotSpot of the drag item is not respected - the cursor should be in the center of the item, not on the top left (see attached image).
It works when the DragHandler is attached to an existing item which is then moved. I know I can do it like that in this example, but it is not possible in our "real" application where this occurs. So besides a fix, any workaround that still allows creation of the drag item on-the-fly is appreciated.
import QtQuick Window { id: win width: 640 height: 480 visible: true title: "Sandbox" Text { anchors.centerIn: parent text: 'Start dragging anywhere' } DragHandler { id: dragHandler target: null onActiveChanged: () => { if (dragHandler.active) { const dragItem = dragComp.createObject(win); dragItem.x = dragHandler.centroid.position.x; dragItem.y = dragHandler.centroid.position.y; dragHandler.target = dragItem; } else { dragHandler.target.destroy(); dragHandler.target = null; } } } Component { id: dragComp Rectangle { id: dragRect color: 'red' width: 60 height: 60 radius: 30 Drag.hotSpot: Qt.point(dragRect.width / 2, dragRect.height / 2) } } }