0
我在PyQt
中遇到了一些鼠标事件的麻烦。这是代码:在条件中断开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
?
我试着这样做,但它总是给我的错误:'A有self.'' –
您可以发布你的代码没有属性运行和堆栈跟踪? – mfessenden