0

I want that when I have changed a line-edit another function gets called, and in that function there is an if-else with Qt.Checked. When I edit the line-edit and then check the checkbox, the text from the line-edit gets written to a variable. But then when I change the line-edit again, it just runs the else in the change function, even if the checkbox is checked. I don't understand why.

Checkbox:

self.filenamecheck.stateChanged.connect(self.changeFileName)

LineEdit:

self.nameLine.textEdited.connect(self.onChangeNameLine)

Functions:

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")

Thank's for your help!

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
jfr
  • 11
  • 4

1 Answers1

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")
ncica
  • 7,015
  • 1
  • 15
  • 37