Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Validating a dateEdit and a Label
Qt 6.11 is out! See what's new in the release blog

Validating a dateEdit and a Label

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 3 Posters 1.0k 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
    LT-K101
    wrote on last edited by
    #1

    Hi,
    I have written a function to validate a dateEdit and a Label which displays an image. I don't know what I'm doing wrong, I would appreciate assistance. Thank you. Below are my lines.

    self.ui.PushButton.clicked.connect(self.my_func)
    
    def my_func(self):
          
        dob = self.ui.Date_of_Birth_dateEdit.date().toString()
        pixmap = QPixmap(self.fname)
        self.ui.Display_label.setPixmap(QPixmap(pixmap))  
    
        if dob == '':
           QMessageBox.information(self, "Error", "Select Date Of Birth")
           self.ui.Date_of_Birth_dateEdit.setFocus()
    
     elif  self.ui.Display_label.setPixmap(QPixmap(pixmap)) == ' ':
           self.ui.Display_label.setFocus()
    
     else:
           self.ui.stackedWidget.setCurrentWidget(self.ui.Page_one)
    
    jsulmJ JonBJ 2 Replies Last reply
    0
    • L LT-K101

      Hi,
      I have written a function to validate a dateEdit and a Label which displays an image. I don't know what I'm doing wrong, I would appreciate assistance. Thank you. Below are my lines.

      self.ui.PushButton.clicked.connect(self.my_func)
      
      def my_func(self):
            
          dob = self.ui.Date_of_Birth_dateEdit.date().toString()
          pixmap = QPixmap(self.fname)
          self.ui.Display_label.setPixmap(QPixmap(pixmap))  
      
          if dob == '':
             QMessageBox.information(self, "Error", "Select Date Of Birth")
             self.ui.Date_of_Birth_dateEdit.setFocus()
      
       elif  self.ui.Display_label.setPixmap(QPixmap(pixmap)) == ' ':
             self.ui.Display_label.setFocus()
      
       else:
             self.ui.stackedWidget.setCurrentWidget(self.ui.Page_one)
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @LT-K101 said in Validating a dateEdit and a Label:

      I don't know what I'm doing wrong

      And I don't know what the problem is...
      Also, what does "validate" mean here?
      Can you please explain what you want to do and what does not work?

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

      L 1 Reply Last reply
      0
      • jsulmJ jsulm

        @LT-K101 said in Validating a dateEdit and a Label:

        I don't know what I'm doing wrong

        And I don't know what the problem is...
        Also, what does "validate" mean here?
        Can you please explain what you want to do and what does not work?

        L Offline
        L Offline
        LT-K101
        wrote on last edited by
        #3

        @jsulm I want to prompt the user, if the user leave a field empty and want to move to the next page by clicking on a Qpushbutton. The App should display a message using a Qmessagebox and setfocus on the empty field so the user will know the exact field which is empty. I used same logic for QLineEdit and it works fine but for QdateEdit and QLabel it does not work.

        1 Reply Last reply
        0
        • L LT-K101

          Hi,
          I have written a function to validate a dateEdit and a Label which displays an image. I don't know what I'm doing wrong, I would appreciate assistance. Thank you. Below are my lines.

          self.ui.PushButton.clicked.connect(self.my_func)
          
          def my_func(self):
                
              dob = self.ui.Date_of_Birth_dateEdit.date().toString()
              pixmap = QPixmap(self.fname)
              self.ui.Display_label.setPixmap(QPixmap(pixmap))  
          
              if dob == '':
                 QMessageBox.information(self, "Error", "Select Date Of Birth")
                 self.ui.Date_of_Birth_dateEdit.setFocus()
          
           elif  self.ui.Display_label.setPixmap(QPixmap(pixmap)) == ' ':
                 self.ui.Display_label.setFocus()
          
           else:
                 self.ui.stackedWidget.setCurrentWidget(self.ui.Page_one)
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @LT-K101 said in Validating a dateEdit and a Label:

          dob = self.ui.Date_of_Birth_dateEdit.date().toString()
          ...
          if dob == '':
          

          Did you check to see whether this can ever return the '' empty string? I don't think it can.

          if the user leave a field empty

          Could you explain how the user gets to leave a QDateEdit empty? I don't think he can.

          1 Reply Last reply
          0

          • Login

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