Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to avoid Null or empty value in QLineedit of Pyqt5
QtWS25 Last Chance

How to avoid Null or empty value in QLineedit of Pyqt5

Scheduled Pinned Locked Moved Unsolved General and Desktop
pyqt5pycharmsqlite3python3
3 Posts 3 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lalremruata
    wrote on 30 Jun 2021, 10:38 last edited by
    #1

    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.

    J J 2 Replies Last reply 30 Jun 2021, 11:11
    0
    • L Lalremruata
      30 Jun 2021, 10:38

      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.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 30 Jun 2021, 11:11 last edited by
      #2

      @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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Lalremruata
        30 Jun 2021, 10:38

        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.

        J Offline
        J Offline
        JonB
        wrote on 30 Jun 2021, 18:41 last edited by JonB
        #3

        @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?

        @jsulm

        You should rather use https://doc.qt.io/qt-5/qstring.html#isEmpty

        My understanding is PyQt5's QLineEdit.text() returns a Python str rather than a C++ QString anyway. I never found using QString methods of any use in PyQt5.

        1 Reply Last reply
        2

        1/3

        30 Jun 2021, 10:38

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved