0
我想在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
并尝试进行另一种方法(因为你可以看到上面的)去打开它,我做了一下,但我没有得到我想要的结果。这就是我得到: