[QtGui module]

该QIntValidator类提供了一个验证器,确保一个字符串包含一个指定范围内的有效整数。More…

继承QValidator

Methods

  • __init__ (self, QObject parent = None)
  • __init__ (self, int bottom, int top, QObject parent = None)
  • int bottom (self)
  • QString input fixup (self, QString input)
  • fixup (self, QString input)
  • setBottom (self, int)
  • setRange (self, int bottom, int top)
  • setTop (self, int)
  • int top (self)
  • (QValidator.State, QString, int) validate (self, QString, int)
  • (QValidator.State, int) validate (self, QString, int)

Detailed Description

该QIntValidator类提供了一个验证器,确保一个字符串包含一个指定范围内的有效整数。

使用示例:

  1. [QValidator](docs_qvalidator.html) *validator = new QIntValidator(100, 999, this);
  2. [QLineEdit](docs_qlineedit.html) *edit = new [QLineEdit](docs_qlineedit.html)(this);
  3. // the edit lineedit will only accept integers between 100 and 999
  4. edit->setValidator(validator);

下面,我们提出校验器的一些例子。在实践中,它们通常会被一个小部件如在上面的例子有关。

  1. [QString](docs_qstring.html) str;
  2. int pos = 0;
  3. QIntValidator v(100, 900, this);
  4. str = "1";
  5. v.validate(str, pos); // returns Intermediate
  6. str = "012";
  7. v.validate(str, pos); // returns Intermediate
  8. str = "123";
  9. v.validate(str, pos); // returns Acceptable
  10. str = "678";
  11. v.validate(str, pos); // returns Acceptable
  12. str = "999";
  13. v.validate(str, pos); // returns Intermediate
  14. str = "1234";
  15. v.validate(str, pos); // returns Invalid
  16. str = "-123";
  17. v.validate(str, pos); // returns Invalid
  18. str = "abc";
  19. v.validate(str, pos); // returns Invalid
  20. str = "12cm";
  21. v.validate(str, pos); // returns Invalid

注意,该值999返回中间。值组成的数字位数等于或小于最大值被认为是中间。这样做的目的是因为,可以防止一些是在范围中的位数不一定是最后一个数字类型的。这也意味着,一个中间数可以有前导零。

的最小值和最大值都设置在一个呼叫与setRange(),或者单独用setBottom()和setTop( ) 。

QIntValidator使用其locale()来解释的数目。例如,在阿拉伯语语言环境, QIntValidator将接受阿拉伯数字。此外, QIntValidator始终保证接受了一些根据“C”区域设置。


Method Documentation

  1. QIntValidator.__init__ (self, QObject parent = None)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个验证用parent对象,它接受所有的整数。

  1. QIntValidator.__init__ (self, int bottom, int top, QObject parent = None)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个验证用parent,接受来自整数minimummaximum包容性。

  1. int QIntValidator.bottom (self)
  1. QString input QIntValidator.fixup (self, QString input)

从重新实现QValidator.fixup( ) 。

  1. QIntValidator.fixup (self, QString input)
  1. QIntValidator.setBottom (self, int)
  1. QIntValidator.setRange (self, int bottom, int top)

设置验证程序的范围只接受之间的整数bottomtop包容性。

  1. QIntValidator.setTop (self, int)
  1. int QIntValidator.top (self)
  1. (QValidator.State, QString, int) QIntValidator.validate (self, QString, int)

从重新实现QValidator.validate( ) 。

Returns Acceptable如果input是在有效范围内的整数,Intermediate如果input是一个整数的有效范围内的前缀,并Invalid否则。

如果有效范围只包括正整数(例如, 32到100 ),并input是一个负整数,则无效返回。 (在另一方面,如果该范围包括负整数(例如,-100到-32 )的和input是一个正整数,然后中间返回,因为用户可能只是键入减号(尤其是从右到左的语言) 。

  1. int pos = 0;
  2. s = "abc";
  3. v.validate(s, pos); // returns Invalid
  4. s = "5";
  5. v.validate(s, pos); // returns Intermediate
  6. s = "50";
  7. v.validate(s, pos); // returns Acceptable

默认情况下,pos参数不使用此验证程序。

  1. (QValidator.State, int) QIntValidator.validate (self, QString, int)