我想实现自我拖曳MapQuickItem
。简单的例子:
MapQuickItem {
id: markerItem
sourceItem: Rectangle {
id: sourceRect
color: "red"
width: 20
height: 20
x: 0
y: 0
MouseArea {
drag.target: markerItem
cursorShape: drag.active ? Qt.ClosedHandCursor : Qt.OpenHandCursor
anchors.fill: parent
}
}
Drag.active: true
}
关键是,如果我快速拖动,一旦光标离开标记,拖动就会中断。有没有办法让它正常工作?
答案 0 :(得分:1)
我找到了一种解决方法:使用单独的可拖动QQuickItem
和锚MapQuickItem
:
MapQuickItem {
id: anchor
sourceItem: Item {}
}
Rectangle {
id: handle
property bool dragged: mouseArea.drag.active
color: "red"
width: 20
height: 20
x: anchor.x - width
y: anchor.y - height
MouseArea {
id: mouseArea
enabled: draggable
drag.target: handle
drag.threshold: 0
anchors.fill: parent
cursorShape: dragged ? Qt.ClosedHandCursor : Qt.OpenHandCursor
}
Connections {
target: anchor
onXChanged: if (!dragged) x = anchor.x - width
onYChanged: if (!dragged) y = anchor.y - height
}
onXChanged: if (dragged) anchor.x = x + width
onYChanged: if (dragged) anchor.y = y + height
Drag.active: true
}
使用动态填充的QML Map
并不是非常方便,但可以完成工作