Digits displaying issue in pyqt



  • 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,


  • Lifetime Qt Champion

    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}"
    

  • Qt Champions 2018

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



  • @jsulm Yes, it is working. Thanks alot.

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


  • @SGaist Thank you so much.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.