我想要实现自拖式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
}
关键是,如果我拖曳快,拖拽就会在光标离开标记时被打断。有办法让它正常工作吗?
发布于 2017-03-27 07:13:41
我找到了一个解决办法:使用单独的可拖放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
并不是非常方便,但它可以完成以下工作
https://stackoverflow.com/questions/42992067
复制相似问题