我希望更改行编辑后会调用另一个函数,并且该函数中有一个Qt.Checked
的if-else。当我编辑行编辑,然后选中复选框时,行编辑中的文本将写入变量。但是,当我再次更改行编辑时,即使选中了该复选框,它也仅在更改功能中运行else
。我不明白为什么。
复选框:
self.filenamecheck.stateChanged.connect(self.changeFileName)
LineEdit:
self.nameLine.textEdited.connect(self.onChangeNameLine)
功能:
def onChangeNameLine(self,state):
self.changeFileName(self)
print("Filename changed")
def changeFileName(self, state):
name = self.nameLine.text()
print("Called change function")
if state == Qt.Checked:
self.filenameLine.setText(name)
print("called change if")
else:
self.filenameLine.setText('')
print("called change else")
谢谢您的帮助!
答案 0 :(得分:0)
def onChangeNameLine(self):
self.changeFileName()
print("Filename changed")
def changeFileName(self):
name = self.nameLine.text()
print("Called change function")
if self.filenamecheck.isChecked():
self.filenameLine.setText(name)
print("called change if")
else:
self.filenameLine.setText('')
print("called change else")