我需要在两个类之间更改两个变量的值,并在每次更改后不断更新它们。
这是代码:
class Window(QMainWindow):
varA = None
varB = None
def __init__(self):
#A lot of stuff in here to create a matplotlib figure
self.linedit = LineEdit(self) #Added while editing
self.figure_canvas.mpl_connect("button_press_event", self.A)
self.figure_canvas.mpl_connect("button_release_event", self.B)
def A(self, event):
varA = event.xdata
#I need to change from here the value of variable1 in class 'LineEdit'
self.linedit.variable1 = LineEdit.varA #Added while editing
def B(self, event(:
varB = event.xdata
#I need to change from here the value of variable2 in class 'LineEdit'
self.linedit.variable2 = LineEdit.varB #Added while editing
class LineEdit(QDialog):
variable1 = None
variable2 = None
def __init__(self, parent):
QDialog.__init__(self, None)
#I open a QDialog.ui file which have 2 QLineEdit
def C(self):
#Here i need to change the value of variable1 and variable2 and update those value
#so i can show them
self.lineEdit.setText(str(self.variable1))
self.lineEdit2.setText(str(self.variable2))
我想要做的是在我点击它和释放按钮时保存鼠标的坐标。完成此操作后,必须在QLineEdit
文件的ui
中显示已保存的坐标。
我怎样才能做到这一点?还有另一种方法吗?
希望你能帮助我。
我添加了你给我的建议。我之前尝试过这个但它不起作用,我的意思是当我点击matplotlib图时它不会改变值。