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?

asked Jun 13, 2015 at 6:15
0

1 Answer 1

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())))
Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
answered Jun 13, 2015 at 10:34
1
  • You could also override the messageEmitted method to display a message to the user. Commented Jul 25, 2015 at 9:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.