Use a popup. You can trigger a popup anywhere, using the QMenu.exec_
method and passing the point at which you want the menu to appear.
I created a button that remembered where it was clicked, and connected that to the method to create and display the popup.
class MemoryButton(QPushButton):
def __init__(self, *args, **kw):
QPushButton.__init__(self, *args, **kw)
self.last_mouse_pos = None
def mousePressEvent(self, event):
self.last_mouse_pos = event.pos()
QPushButton.mousePressEvent(self, event)
def mouseReleaseEvent(self, event):
self.last_mouse_pos = event.pos()
QPushButton.mouseReleaseEvent(self, event)
def get_last_pos(self):
if self.last_mouse_pos:
return self.mapToGlobal(self.last_mouse_pos)
else:
return None
button = MemoryButton("Click Me!")
def popup_menu():
popup = QMenu()
menu = popup.addMenu("Do Action")
def _action(check):
print "Action Clicked!"
menu.addAction("Action").triggered.connect(_action)
popup.exec_(button.get_last_pos())
button.clicked.connect(popup_menu)