1

I would like to have a pop-up menu when right-clicking the MapCanvas
(the identifyFeatures tool does it...)

Could anybody give me a starting point on how to achieve this?

0
5

Should have searched a bit more (...) :

class showMenu(QgsMapTool):

    def __init__(self, iface):
        canvas = iface.mapCanvas()
        QgsMapTool.__init__(self,canvas)
        self.canvas = canvas

    def canvasPressEvent(self,e):
        if e.button() == Qt.RightButton:
            menu = QMenu()
            quitAction = menu.addAction("AnyAction")
            action = menu.exec_(self.canvas.mapToGlobal(QPoint(e.pos().x()+5, e.pos().y())))
1
  • You could also override the messageEmitted method to display a message to the user.
    – Matt
    Jul 25 '15 at 9:10

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .