How to avoid Null or empty value in QLineedit of Pyqt5
-
I tried to validate the QLineedit not to be empty without success.
I did
validator = QRegExpValidator(QRegExp(r'[0-9]+')) self.lineEdit_2.setValidator(validator)
it is working.
But
def temp_var(self, text): cur_txt = text if cur_txt == 'Cheque' or cur_txt == 'Wire Transfer' or self.lineEdit_2.text() == "": self.groupBox_3.show() self.pushButton_7.hide() self.pushButton_7.setEnabled(False) else: self.groupBox_3.hide() self.pushButton_7.show() self.pushButton_7.setEnabled(True)
all works fine but the pushbutton is always enabled even the self.lineEdit_2 is empty.
I request your help. (I am a self-learner and could not find solution in the web.
-
@Lalremruata said in How to avoid Null or empty value in QLineedit of Pyqt5:
or self.lineEdit_2.text() == ""
You should rather use https://doc.qt.io/qt-5/qstring.html#isEmpty
-
@Lalremruata said in How to avoid Null or empty value in QLineedit of Pyqt5:
even the self.lineEdit_2 is empty.
Are you really 100% sure? I used PyQt5 and I'm pretty sure
self.lineEdit_2.text() == ""
would work as expected. Get rid of all your other code and behaviour and check just this in a tiny program?You should rather use https://doc.qt.io/qt-5/qstring.html#isEmpty
My understanding is PyQt5's
QLineEdit.text()
returns a Pythonstr
rather than a C++QString
anyway. I never found usingQString
methods of any use in PyQt5.