【发布时间】:2020-04-23 10:39:20
【问题描述】:
我在地图上使用 MapQuickItem 作为委托组件。我有三个组件。单击组件时,我想更改委托组件的颜色。其余颜色相同。如何更改仅选定组件颜色的颜色
Plugin
{
id: hereMaps
name: "here"
PluginParameter { name: "here.app_id"; value: "oBB4FivcP23m2UZQCj8K" }
PluginParameter { name: "here.token"; value: "P-D8XRRGeVt0YphUuOImeA" }
}
Map {
id: map
anchors.fill: parent
activeMapType: supportedMapTypes[1];
zoomLevel: 18
plugin: hereMaps
center: QtPositioning.coordinate(19.997454, 73.789803)
MapItemView {
id: markerItem
model: [
{ id: "marker1", color: "red" },
{ id: "marker2", color: "red" },
{ id: "marker3", color: "red" }
]
delegate: mapMarkerComponent
}
Component {
id : mapMarkerComponent
MapQuickItem {
id: mapMarker
coordinate: QtPositioning.coordinate(19.997454, 73.789803)
sourceItem: Rectangle {
id: handle
color: modelData.color
width: 40
height: 40
MouseArea {
drag.target: parent
anchors.fill: parent
onClicked: {
handle.color = "green"
}
}
}
onCoordinateChanged: {
console.log(modelData.id + ":" + coordinate);
}
}
}
}
【问题讨论】:
-
这段代码已经这样做了:将点击标记的颜色从红色变为绿色......更精确。你想达到什么目标?
-
当我点击那个矩形组件时,我想改变它的颜色。我的代码中有三个矩形组件。当我单击第一个矩形时,它变为绿色,其他两个为红色。当我单击第二个矩形时,我想更改第二个矩形的颜色,第一个和第三个变为红色。但是在我的代码中,当我首先单击第二个矩形时,它仍然是绿色的。如何使第一个和第三个矩形变为红色,并且仅将单击的矩形变为红色
标签: qt qml maps qqmlcomponent