Search code examples
pythonqtpysideqlineeditqpushbutton

How to disable a Button unless a Edit Field isn't empty?


I've got a QLineEdit field and a QPushButton. The button should be disabled as long the QLineEdit is empty.

How to do that?


Solution

  • well, i'll just conclude what they said in the comments, some code like

    self.btnButton.setDisable(True)
    self.leInput.textChanged.connect(self.disableButton)
    def disableButton(self):
        if len(self.leInput.text()) > 0:
            self.btnButton.setDisable(False)
    

    and yes, the signals / function names are obvious, you need to check more on the docs / tutor