Making the border of a Mappolygon clickable - QML

557 views Asked by At

I have been trying to make the border of a MapPolygon clickable in QML by the following code:

MapPolygon{
        id: _poly
        border.color: "black"
        border.width: 4
        color: "transparent"
        visible: false
        path: []
        MouseArea{
            id: _polyMousearea
            anchors.fill: _poly.border
            acceptedButtons: Qt.LeftButton
            onClicked: {
                var coord = _map.toCoordinate(Qt.point(flightMapMouseArea.mouseX,flightMapMouseArea.mouseY))
console.log(coord )

                }

            }
        }

    }

I get the following error:

Unable to assign QDeclarativeMapLineProperties to QQuickItem at the line : anchors.fill: _poly.border

Any way to get around this error and make the border clickable?

Thanks

1

There are 1 answers

1
Kevin Krammer On

Anchors are used to position QtQuick Item objects relative to another, the border of this element is apparently not an element itself, just a normal grouped property.

Assuming that the path contains a QtQuick Path one option you have is to make the MouseArea fill the whole item, and then use the mouse position in the onClicked handler to check with the path's elements on whether they are hit or not.