MapQuickItem 在 model/view 委托中不可见
MapQuickItem invisible in model/view delegate
在 QtCreator 中添加一个新的 QtQuick 应用程序并用以下代码替换 main.qml
将导致应用程序在鼠标单击的位置添加一个 MapCircle
。但是,如果我将 delegate: MapCircle [...]
替换为自定义 delegate: MapQuickItem [...]
,该项目将被添加(请参阅控制台日志),但它不会显示。
与Map {...}
内的固定对象相同的MapQuickItem [...]
块和一些坐标将被显示。
我是不是遗漏了什么或者这可能是一个错误?
import QtQuick 2.6
import QtQuick.Window 2.2
import QtPositioning 5.5
import QtLocation 5.6
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
MainForm {
anchors.fill: parent
ListModel {
id: mapModel
}
Map {
id: map
anchors.centerIn: parent
anchors.fill: parent
plugin: Plugin {
name: "osm" // "mapboxgl", "esri", ...
}
MapItemView {
model: mapModel
/* // the following code won't display the MapQuickItem item
delegate: MapQuickItem {
sourceItem: Rectangle {
width: 14
height: 14
color: "#2ad3f9"
radius: 7
}
anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2)
coordinate {
latitude: lat
longitude: lon
}
} */
// this works as expected
delegate: MapCircle {
radius: 8000
color: 'blue'
center {
latitude: lat
longitude: lon
}
}
}
MouseArea
{
anchors.fill: parent
onClicked:
{
var coord = map.toCoordinate(Qt.point(mouse.x, mouse.y))
mapModel.append({lat : coord.latitude, lon: coord.longitude});
console.log(mapModel.count)
}
}
}
}
}
将坐标显式转换为 QtPositioning.coordinate
即可:
MapItemView {
model: mapModel
delegate: MapQuickItem {
sourceItem: Rectangle {
width: 14
height: 14
color: "#2ad3f9"
radius: 7
}
anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2)
coordinate : QtPositioning.coordinate(lat, lon)
}
}
在 QtCreator 中添加一个新的 QtQuick 应用程序并用以下代码替换 main.qml
将导致应用程序在鼠标单击的位置添加一个 MapCircle
。但是,如果我将 delegate: MapCircle [...]
替换为自定义 delegate: MapQuickItem [...]
,该项目将被添加(请参阅控制台日志),但它不会显示。
与Map {...}
内的固定对象相同的MapQuickItem [...]
块和一些坐标将被显示。
我是不是遗漏了什么或者这可能是一个错误?
import QtQuick 2.6
import QtQuick.Window 2.2
import QtPositioning 5.5
import QtLocation 5.6
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
MainForm {
anchors.fill: parent
ListModel {
id: mapModel
}
Map {
id: map
anchors.centerIn: parent
anchors.fill: parent
plugin: Plugin {
name: "osm" // "mapboxgl", "esri", ...
}
MapItemView {
model: mapModel
/* // the following code won't display the MapQuickItem item
delegate: MapQuickItem {
sourceItem: Rectangle {
width: 14
height: 14
color: "#2ad3f9"
radius: 7
}
anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2)
coordinate {
latitude: lat
longitude: lon
}
} */
// this works as expected
delegate: MapCircle {
radius: 8000
color: 'blue'
center {
latitude: lat
longitude: lon
}
}
}
MouseArea
{
anchors.fill: parent
onClicked:
{
var coord = map.toCoordinate(Qt.point(mouse.x, mouse.y))
mapModel.append({lat : coord.latitude, lon: coord.longitude});
console.log(mapModel.count)
}
}
}
}
}
将坐标显式转换为 QtPositioning.coordinate
即可:
MapItemView {
model: mapModel
delegate: MapQuickItem {
sourceItem: Rectangle {
width: 14
height: 14
color: "#2ad3f9"
radius: 7
}
anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2)
coordinate : QtPositioning.coordinate(lat, lon)
}
}