Search code examples
qtqmlqt5openstreetmap

QML osm MapItemView MapPolyline opacity


I have QQuickWidget and QML in it

Plugin {
    id: mapPlugin
    objectName: "mapPlugin"
    name: "osm"

    ...
}

Map {
    id: map
    objectName: "map"
    ....

    MapItemView {
        id: mapItemPath
        model: mapProxyModel

        delegate: MapPolyline {
            path: pathRole

            line.color: "red"
            line.width: 10
            // opacity: 0.5
       }
       opacity: 0.5
}

actually opacity not working. Why that could be?


Solution

  • To make opacity work on the MapPolyLine you either should set opacity or use Qt.rgba() to create a color with an alpha value appropriate to use your opacity you want to get.

    Plugin {
        id: mapPlugin
        name: "osm"
    }
    
    Map {
        anchors.fill: parent
        plugin: mapPlugin
        center: QtPositioning.coordinate(-27, 153.0)
        zoomLevel: 8
    
        MapPolyline {
            line.width: 10
            line.color: Qt.rgba(0, 1, 0, 0.5)
            //opacity: 0.5
            path: [
                { latitude: -27, longitude: 153.0 },
                { latitude: -27, longitude: 154.1 },
                { latitude: -28, longitude: 153.5 },
                { latitude: -29, longitude: 153.5 }
            ]
        }
    }
    

    enter image description here