Select to view content in your preferred language

Adding a drop down menu to the map

1201
3
Jump to solution
05-26-2021 06:53 AM
FatmaAkdemir
Frequent Contributor

Is there a way to enable user to see a drop down menu when he/she right clicks to the map? And when he selects one of the items in that menu, some action needs to be performed.

0 Kudos
1 Solution

Accepted Solutions
JaredCaccamo
Esri Contributor

Hello again @FatmaAkdemir ,

 

In that case you can use "mousePressed" with "RightButton" to catch the mouse events and "QMenu::exec" to open a context menu. Or if you don't want to use a menu, you could use "QPushButton" instead.

Documentation for C++:

https://developers.arcgis.com/qt/cpp/api-reference/esri-arcgisruntime-mapgraphicsview.html

https://doc.qt.io/qt-5/qmenu.html#exec-1 

https://doc.qt.io/qt-5/qpushbutton.html 

 

Sincerely,

Jared

View solution in original post

0 Kudos
3 Replies
JaredCaccamo
Esri Contributor

Hello @FatmaAkdemir,

 

Yes using a combination of the MapView and QtQuick.Controls you definitely could. You would need to listen for the MapView.onMouseClicked signal and then use mouse.x and mouse.y then use those to update the x and y of the QtQuick.Controls ComboBox(drop down menu) which can take a ListModel(list of items in that menu) then you can listen for the ComboBox.onActivated(int index) signal for the selection from that list and use the index to know which model from that list was selected and do whatever following action you would like.

Here is an example:

import QtQuick 2.6
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
import Esri.ArcGISRuntime 100.11

ApplicationWindow {
    id: appWindow
    width: 800
    height: 600
    title: "Example"

    property var myExModel : ["apple", "pie", "cherry", "pie"]

    // add a mapView component
    MapView {
        anchors.fill: parent
        // set focus to enable keyboard navigation
        focus: true

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

        onMouseClicked: {
            myComboBox.x = mouse.x;
            myComboBox.y = mouse.y;
            myComboBox.visible = true;
        }
    }

    ComboBox {
        id: myComboBox
        model: myExModel
        visible: false

        onActivated: {
            myDialog.text = myExModel[index];
            visible = false;
            myDialog.open();
        }
    }

    MessageDialog {
        id: myDialog
    }
}

 

Hope you find this helpful!

 

Sincerely,

Jared

FatmaAkdemir
Frequent Contributor

Hi @JaredCaccamo ,

Thank you for the detailed answer. Unfortunately I am not using QML. Should I use QComboBox in this case? In fact I only need a pop-up button ("Delete") when user right clicks on a graphic. After user clicks on that button, graphic will be deleted from the map.

0 Kudos
JaredCaccamo
Esri Contributor

Hello again @FatmaAkdemir ,

 

In that case you can use "mousePressed" with "RightButton" to catch the mouse events and "QMenu::exec" to open a context menu. Or if you don't want to use a menu, you could use "QPushButton" instead.

Documentation for C++:

https://developers.arcgis.com/qt/cpp/api-reference/esri-arcgisruntime-mapgraphicsview.html

https://doc.qt.io/qt-5/qmenu.html#exec-1 

https://doc.qt.io/qt-5/qpushbutton.html 

 

Sincerely,

Jared

0 Kudos