Edip Ahmet
Edip Ahmet

Reputation: 525

Menu pops up at center rather than touched place

When trying to create a menu on map, menu pops up at center of the map rather than touched place on map when using onPressAndHold on Android. However the same code works correctly on desktop (Ubuntu). When press and hold with mouse on map, the menu pops up from mouse position on Ubuntu. I also tried Map Viewer example in Qt 5.13, it is the same. Is it possible to fix the menu position for Android? Thanks.

import QtQuick.Window 2.2
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtLocation 5.11
import QtPositioning 5.11

Window {
    id: root
    visible: true
    width: 640
    height: 480
    Plugin {
        id: mapPlugin
        name: "osm"
    }
    Menu {
        id:mapPopupMenu
        Action {
            text: qsTr("Get coordinate")
        }
    }

    Map {
        id: map
        anchors.fill: parent
        plugin: mapPlugin
        zoomLevel: 14
        center:  QtPositioning.coordinate(40,40)
        activeMapType: supportedMapTypes[1]
    }

    MouseArea {
        anchors.fill: parent
        onPressAndHold:mapPopupMenu.popup()
    }
}

Upvotes: 0

Views: 87

Answers (1)

Edip Ahmet
Edip Ahmet

Reputation: 525

Thanks to Ramkumar R's answer. Now it works when using mouse.x and mouse.y in popup:

MouseArea {
        anchors.fill: parent
        onPressAndHold:mapPopupMenu.popup(mouse.x, mouse.y)
    }

Upvotes: 1

Related Questions