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?


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

class showMenu(QgsMapTool):

def __init__(self, iface):
    canvas = iface.mapCanvas()
    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())))
  • You could also override the messageEmitted method to display a message to the user. – Matt Jul 25 '15 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.