QValidator 类提供对输入文本的验证。 更多...
继承 QObject .
Inherited by QDoubleValidator , QIntValidator and QRegExpValidator .
QValidator 类提供对输入文本的验证。
类本身是抽象的。2 个子类 QIntValidator and QDoubleValidator , provide basic numeric-range checking, and QRegExpValidator provides general checking using a custom regular expression.
If the built-in validators aren't sufficient, you can subclass QValidator. The class has two virtual functions: validate () 和 fixup ().
validate () must be implemented by every subclass. It returns Invalid , 中间体 or Acceptable depending on whether its argument is valid (for the subclass's definition of valid).
这 3 种状态需要一些解释。 Invalid 字符串是 clearly 无效的。 中间体 is less obvious: the concept of validity is difficult to apply when the string is incomplete (still being edited). QValidator defines 中间体 作为 property of a string that is neither clearly invalid nor acceptable as a final result. Acceptable means that the string is acceptable as a final result. One might say that any string that is a plausible intermediate state during entry of an Acceptable 字符串是 中间体 .
这里是一些范例:
fixup () is provided for validators that can repair some user errors. The default implementation does nothing. QLineEdit ,例如,会调用 fixup () if the user presses Enter (or Return) and the content is not currently valid. This allows the fixup () function the opportunity of performing some magic to make an Invalid string Acceptable .
验证器拥有区域设置,设置采用 setLocale (). It is typically used to parse localized data. For example, QIntValidator and QDoubleValidator use it to parse localized representations of integers and doubles.
通常把 QValidator 用于 QLineEdit , QSpinBox and QComboBox .
This enum type defines the states in which a validated string can exist.
| 常量 | 值 | 描述 |
|---|---|---|
| QValidator.Invalid | 0 | 字符串是 clearly 无效的。 |
| QValidator.Intermediate | 1 | The string is a plausible intermediate 值。 |
| QValidator.Acceptable | 2 | The string is acceptable as a final result; i.e. it is valid. |
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
设置验证器。 parent parameter is passed on 到 QObject 构造函数。
此函数试图改变 input to be valid according to this validator's rules. It need not result in a valid string: callers of this function must re-test afterwards; the default does nothing.
此函数的重实现可以改变 input even if they do not produce a valid string. For example, an ISBN validator might want to delete every character except digits and "-", even if the result is still not a valid ISBN; a surname validator might want to remove whitespace from the start and end of the string, even if the resulting string is not in the list of accepted surnames.
Returns the locale for the validator. The locale is by default initialized to the same as QLocale().
另请参阅 setLocale () 和 QLocale.QLocale ().
设置 locale that will be used for the validator. Unless setLocale has been called, the validator will use the default locale set with QLocale.setDefault (). If a default locale has not been set, it is the operating system's locale.
另请参阅 locale () and QLocale.setDefault ().
This method is abstract and should be reimplemented in any sub-class.
此虚函数返回 Invalid if input 是无效的 according to this validator's rules, 中间体 if it is likely that a little more editing will make the input acceptable (e.g. the user types "4" into a widget which accepts integers between 10 and 99), and Acceptable 若 input is valid.
函数可以改变 input and pos (the cursor position) if required.
This method is abstract and should be reimplemented in any sub-class.