Я хотел бы открыть контекстное меню в фигуре matplotlib, в то время и в позиции, которую я нажимаю правой кнопкой мыши на рисунке. Я хочу открыть его в координатах, где я нажимаю кнопку, и получаю эти координаты.Откройте контекстное меню в циферблате matplotlib
Это мой код до сих пор:
classs Figure(QMainWindow):
x1 = 0 #I made this variables to get the coordinates and use it in
x2 = 0 # another methods too
def __init__(self):
#A lot of stuff in here to create the figure
def right_click_press(self, event):
if event.button == 3: #"3" is the right button
print "you click the right button"
print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(
event.button, event.x, event.y, event.xdata, event.ydata)
#Get the coordinates of the mouse click
Figure.x1 = event.xdata
Figure.y1 = event.ydata
#I create the action
noteAction_2 = QAction(QIcon(""), "Insert note",self,
triggered = self.openDialog)
#I create the context menu
self.popMenu = QMenu(self)
self.popMenu.addAction(noteAction_2)
cursor = QCursor()
print cursor.pos()
#self.connect(self.figure_canvas, SIGNAL("clicked()"), self.context_menu)
#self.popMenu.exec_(self.mapToGlobal(event.globalPos()))
self.popMenu.exec_()
def context_menu(self):
pass
Я попытался globalPos
, mapToGlobal
, pos
и пытается сделать еще один метод (как вы можете видеть выше), чтобы получить, чтобы открыть его, где я сделать щелчок, но Я не получаю результата, которого хочу. Это то, что я получаю: