[英]PyQt: QLineEdit input mask for only Integer or only String and length restriction
These are the 2 questions(both can be solved by InputMask?)这是两个问题(都可以通过 InputMask 解决?)
I'm not sure how I can implement the first part in real-time,ie, the user types a max of 16, nothing beyond 16 appears.我不确定如何实时实现第一部分,即用户输入最多 16 个,不会出现超过 16 个。
This is my code(not working) for the 2nd part of the question:这是我的问题第二部分的代码(不起作用):
self.onlyInt = QIntValidator()
self.lineEdit_15.setValidator(self.onlyInt)
det15=str(self.lineEdit_15.text())
list_val.append(det15)
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:相比之下,第二个 QIntValidator 问题仅适用于等于
2147483647
的最大值,因为它是最大整数:2**31-1,解决方案是使用正则表达式:
rx = QRegExp("\d+")
self.lineedit_15.setValidator(QRegExpValidator(rx))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.