Select to view content in your preferred language

Question on getting MouseEvent in QML

975
2
Jump to solution
04-21-2021 07:15 PM
Tkm_Knj
Emerging Contributor

Hi.

I use Runtime version 100.8 and Qt 5.15.0 .

The code is almost the same, but I can't get MouseEvent.

Connections{
    target: mainMap

    //can't get
    function onMouseClicked() {
        var clickP = mainMap.screenToLocation(mouse.x, mouse.y)
        console.log(mouse.x)
    }

    //can get
    onMouseClicked: {
        var clickP = mainMap.screenToLocation(mouse.x, mouse.y)
        console.log(mouse.x)
    }    
}

 

On the side where I can get MouseEvent, I will get the following error.

QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... } 

 

What should I do in this situation?

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi there.

I'm also a tad confused with the new connection syntax in Qt 5.15, will take some time to get used to.
Here's a formulation that worked for me, try giving this a go.

MapView {
    id : mapView
    anchors.fill: parent
    focus: true

    Map {
        // add the ArcGISStreets basemap to the map
        initBasemapStyle: Enums.BasemapStyleArcGISStreets
    }

    Connections {
        target: mapView
        function onMouseClicked(mouseEvent) {
            console.log("x:", mouseEvent.x, "y:", mouseEvent.y)
        }
    }
}

 

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable

Hi there.

I'm also a tad confused with the new connection syntax in Qt 5.15, will take some time to get used to.
Here's a formulation that worked for me, try giving this a go.

MapView {
    id : mapView
    anchors.fill: parent
    focus: true

    Map {
        // add the ArcGISStreets basemap to the map
        initBasemapStyle: Enums.BasemapStyleArcGISStreets
    }

    Connections {
        target: mapView
        function onMouseClicked(mouseEvent) {
            console.log("x:", mouseEvent.x, "y:", mouseEvent.y)
        }
    }
}

 

0 Kudos
Tkm_Knj
Emerging Contributor

Thanks!

It code is correct.

I can get MouseEvent.

0 Kudos