How to avoid Null or empty value in QLineedit of Pyqt5


Joined
Jun 30, 2021
Messages
6
Reaction score
0
I tried to validate the QLineedit not to be empty without success.

I did

Code:
validator = QRegExpValidator(QRegExp(r'[0-9]+'))
self.lineEdit_2.setValidator(validator)
it is working.

But

Code:
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.
 
Ad

Advertisements

Joined
Jul 3, 2021
Messages
37
Reaction score
1
Putting PyQT in your thread title would've been nice.

Anyway, add a breakpoint and watcher to your lineEdit's strings and look at it's value compared to it's data type.
Report here your result.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top