【发布时间】:2016-06-22 09:22:02
【问题描述】:
我在PyQt 中遇到了一些鼠标事件问题。这是代码:
class A(QMainWindow):
var = None
def __init__(self):
QMainWindow.__init__(self)
#Here I draw a matplotlib figure
self.figure_canvas = FigureCanvas(Figure())
layout.addWidget(self.figure_canvas, 10)
self.axes = self.figure_canvas.figure.add_subplot(211)
#I created a toolbar for the figure and I added a QPushButton
self.btn_selection_tool = QPushButton()
self.navigation_toolbar.addWidget(self.btn_selection_tool)
self.connect(self.btn_selection_tool, SIGNAL("clicked()"), self.B)
def B(self):
if self.var == 1:
cid = self.figure_canvas.mpl_connect("press_button_event", self.C)
def C(self, event):
x = xdata.event
#I draw a line every time I click in the canvas
def D(self):
#Here I tried to call this method and disconnect the signal
self.figure_canvas.mpl_disconnect(cid)
问题是我无法使用以下方法断开鼠标事件的信号:
self.figure_canvas.mpl_disconnect(cid)
什么都没有发生,我每次点击都会画一条线。鼠标事件仍处于连接状态。
如何断开信号?也许使用另一个QPushButton?
【问题讨论】:
标签: python python-2.7 matplotlib pyqt