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 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.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • L Lalremruata

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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

        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.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on 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

        • Login

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