我有一套QPointF
在MarkerModel
,它从AbstractListModel
的子类。每个这样的标记都具有一个状态,这取决于它们被着色。我想在地图上绘制所有这些标记以及连接所有具有特定状态的点的多段线。我将从C++端更新模型。这是我的QMLAbstractItemModel到QML路由
Map {
id: map
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(22.5726, 88.3639)
zoomLevel: 14
MapItemView {
model: markerModel
// delegate: markerDelegate // markerDelegate works
delegate: routeDelegate // routeDelegate does not work
}
Component {
id: markerDelegate
MapQuickItem{
anchorPoint: Qt.point(2.5, 2.5)
coordinate: QtPositioning.coordinate(position.x, position.y)
zoomLevel: 0
sourceItem: Rectangle{
width: settings.marker_size;
height: settings.marker_size;
radius: settings.marker_size/2;
color: settings.marker_colors[status]
border.color: "white"
border.width: 1
}
}
}
Component{
id: routeDelegate
MapRoute{
route: markerModel
line.color: "blue"
line.width: 5
smooth: true
opacity: 0.8
}
}
}
我其实想要两个,点和场景上的折线。然而,因为我不知道如何将它们放在场景中,所以我首先尝试使用markerDelegate
来显示模型中的点,它们都可以工作。现在我想以routeDelegate
作为折线查看这些点。但是,抱怨
无法MarkerModel分配给QDeclarativeGeoRoute
对不起,我不明白,'markerModel'实际上是'AbstractListModel'的子类。我不知道如何在QT中创建'RouteModel'(C++) –
好吧,对不起,我对这个例子感到困惑,也许你可以解决它只保留你使用的委托? 在任何情况下,如果您想要将MapRoute与不是RouteModel的模型一起使用,则必须在模型中通过您提供Route对象(QDeclarativeGeoRoute)来定义角色。 编辑:实际上,现在我再次读你的问题,你不能使用QPointF来创建MapRoute或MapPolyline。您首先必须将它们转换为QGeoCoordinates。 –
如何从C++创建QDeclarativeGeoRoute对象?那个班在哪里? QML中的 –