如何设置 PyQt5 QIntValidator 的顶部和底部?

How to set PyQt5 QIntValidator's top and bottom?

我有一个类似下面代码的行编辑。在 3 个不同的代码中我有 2 个不同的问题:

self.rnr_id_num_le = QLineEdit()
self.rnr_id_num_le.setValidator(QIntValidator(9999999999, 0))

使用这个我可以直接输入 0 和 1。

self.rnr_id_num_le = QLineEdit()
self.rnr_id_num_le.setValidator(QIntValidator(0, 9999999999))

用这个我只能输入0.

我需要它来获得这样的数字:5236147891(位数很重要。如果我不在 QIntValidator 中输入任何数字,它不会让我输入这么大的数字)

基于 http://pyqt.sourceforge.net/Docs/PyQt4/qintvalidator.html#QIntValidator-2 第二个必须工作;但它没有:(

编辑:

好的,显然它的最高点,如果可以的话,比我需要的少一位数。你知道另一种方法来验证我的 QLineEdit,或者增加 QIntValidator 的顶部吗?

支持无限浮点值的QIntValidator class only supports signed values in the range -2147483648 to 2147483647. If you need values outside this range, use QDoubleValidator

您可以创建 QDoubleValidator 的简单子 class 来调整行为,使其更像 QIntValidator:

class BigIntValidator(QtGui.QDoubleValidator):
    def __init__(self, bottom=float('-inf'), top=float('inf')):
        super(BigIntValidator, self).__init__(bottom, top, 0)
        self.setNotation(QtGui.QDoubleValidator.StandardNotation)

    def validate(self, text, pos):
        if text.endswith('.'):
            return QtGui.QValidator.Invalid, text, pos
        return super(BigIntValidator, self).validate(text, pos)