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. Digits displaying issue in pyqt
Forum Updated to NodeBB v4.3 + New Features

Digits displaying issue in pyqt

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 555 Views 2 Watching
  • 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.
  • monamourM Offline
    monamourM Offline
    monamour
    wrote on last edited by
    #1

    Dear All,

     I have created two fields in UI form in pyqt, (QLineEdit) for 'ID' and (QTextBrowser) for 'D.O.B' which is  dateOfBirth.
    

    The idea is, from the first field (ID) it can be extract the birthday and print it into the second field (D.O.B).

    Example:

      Text = 285121100762
      then after press 'Tab' from the keyboard or 'Enter' would print it into second field: [D.O.B = 11/12/1985]
    

    So, the code as follows,

    
    
    def EQ(self):
            number = self.lineEdit.text()
            digit = int(number[5])
            digit1 = int(number[6])
            digit2 = int(number[3])
            digit3 = int(number[4])
            digit4 = int(number[1])
            digit5 = int(number[2])
            self.textBrowser.append(str(digit,digit1,'/',digit2,digit3,'/','19',digit4,digit5))
    

    The last line is not displaying because so many parameters that more than three. However, the last is working in pure python code by print command.

    Any idea?

    Many thanks in advance,

    jsulmJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Because you can't use str like print.

      Use python's string building facilities. For example:

      dob = "{}{}/{}{}/{}{}".format(digit, digit1, digit2, digit3, digit4, digit5)
      

      On more recent versions of python:

      dob = f"{digit}{digit1}/{digit2}{digit3}/{digit3}{digit5}"
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      monamourM 1 Reply Last reply
      2
      • monamourM monamour

        Dear All,

         I have created two fields in UI form in pyqt, (QLineEdit) for 'ID' and (QTextBrowser) for 'D.O.B' which is  dateOfBirth.
        

        The idea is, from the first field (ID) it can be extract the birthday and print it into the second field (D.O.B).

        Example:

          Text = 285121100762
          then after press 'Tab' from the keyboard or 'Enter' would print it into second field: [D.O.B = 11/12/1985]
        

        So, the code as follows,

        
        
        def EQ(self):
                number = self.lineEdit.text()
                digit = int(number[5])
                digit1 = int(number[6])
                digit2 = int(number[3])
                digit3 = int(number[4])
                digit4 = int(number[1])
                digit5 = int(number[2])
                self.textBrowser.append(str(digit,digit1,'/',digit2,digit3,'/','19',digit4,digit5))
        

        The last line is not displaying because so many parameters that more than three. However, the last is working in pure python code by print command.

        Any idea?

        Many thanks in advance,

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @monamour Shouldn't you do something like

        self.textBrowser.append("%d%d/%d%d/19%d%d" % (digit,digit1,digit2,digit3,digit4,digit5))
        

        in Python?

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

        monamourM 1 Reply Last reply
        0
        • jsulmJ jsulm

          @monamour Shouldn't you do something like

          self.textBrowser.append("%d%d/%d%d/19%d%d" % (digit,digit1,digit2,digit3,digit4,digit5))
          

          in Python?

          monamourM Offline
          monamourM Offline
          monamour
          wrote on last edited by monamour
          #4

          @jsulm Yes, it is working. Thanks alot.

          self.textBrowser.append ('%d%d/%d%d/19%d%d' % (digit, digit1,digit2,digit3,digit4,digit5))
          
          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Because you can't use str like print.

            Use python's string building facilities. For example:

            dob = "{}{}/{}{}/{}{}".format(digit, digit1, digit2, digit3, digit4, digit5)
            

            On more recent versions of python:

            dob = f"{digit}{digit1}/{digit2}{digit3}/{digit3}{digit5}"
            
            monamourM Offline
            monamourM Offline
            monamour
            wrote on last edited by
            #5

            @SGaist Thank you so much.

            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