PyQt: QLineEdit input mask for only Integer or only String and length restriction

后端 未结 1 1501
清歌不尽
清歌不尽 2021-01-25 10:11

These are the 2 questions(both can be solved by InputMask?)

  1. I want to restrict the user input to 16 characters only
  2. In a field like \'Age/ID\', I would li
相关标签:
1条回答
  • 2021-01-25 10:33

    To solve the first question we only have to establish a maximum size:

    self.lineedit_15.setMaxLength(16)
    

    In contrast the second QIntValidator question only works up to a maximum equal to 2147483647 since it is the maximum integer: 2**31-1, The solution is to use regular expressions:

    rx = QRegExp("\d+")
    self.lineedit_15.setValidator(QRegExpValidator(rx))
    
    0 讨论(0)
提交回复
热议问题