PySide6.QtGui.QIntValidator¶
- class QIntValidator¶
QIntValidator类提供了一个验证器,确保字符串包含指定范围内的有效整数。更多…概要¶
属性¶
方法¶
def
__init__()def
bottom()def
setBottom()def
setRange()def
setTop()def
top()
信号¶
def
bottomChanged()def
topChanged()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
警告
本节包含从C++自动翻译到Python的代码片段,可能包含错误。
使用示例:
validator = QIntValidator(100, 999, self) edit = QLineEdit(self) # the edit lineedit will only accept integers between 100 and 999 edit.setValidator(validator)
下面我们展示一些验证器的示例。在实际应用中,它们通常会像上面的示例那样与一个小部件相关联。
str = QString() pos = 0 v = QIntValidator(100, 900, self) str = "1" v.validate(str, pos) # returns Intermediate str = "012" v.validate(str, pos) # returns Intermediate str = "123" v.validate(str, pos) # returns Acceptable str = "678" v.validate(str, pos) # returns Acceptable str = "999" v.validate(str, pos) # returns Intermediate str = "1234" v.validate(str, pos) # returns Invalid str = "-123" v.validate(str, pos) # returns Invalid str = "abc" v.validate(str, pos) # returns Invalid str = "12cm" v.validate(str, pos) # returns Invalid
请注意,值
999返回 Intermediate。由等于或小于最大值的数字组成的值被视为中间值。这是有意为之的,因为阻止数字在范围内的数字不一定是最后输入的数字。这也意味着中间数字可以有前导零。最小值和最大值可以通过一次调用
setRange()来设置,或者分别使用setBottom()和setTop()来设置。QIntValidator使用其locale()来解释数字。例如,在阿拉伯语环境中,QIntValidator将接受阿拉伯数字。注意
设置在
locale()上的QLocale::NumberOptions也会影响数字的解析方式。例如,由于默认情况下未设置QLocale::RejectGroupSeparator,验证器将接受分组分隔符。因此,建议使用QLocale::toInt()来获取数值。另请参阅
QDoubleValidatorQRegularExpressionValidatortoInt()Line Edits Example注意
当使用
from __feature__ import true_property时,属性可以直接使用,否则通过访问器函数使用。- property bottomᅟ: int¶
此属性保存验证器的最低可接受值。
默认情况下,此属性的值源自可用的最小有符号整数(-2147483648)。
另请参阅
- Access functions:
- property topᅟ: int¶
此属性保存验证器的最高可接受值。
默认情况下,此属性的值源自可用的最大有符号整数(2147483647)。
另请参阅
- Access functions:
构造一个带有
parent对象的验证器,该对象接受所有整数。- __init__(bottom, top[, parent=None])
- Parameters:
bottom – int
top – int
parent –
QObject
构建一个带有
parent的验证器,该验证器接受从minimum到maximum(包括这两个值)的整数。- bottom()¶
- Return type:
整数
另请参阅
属性
bottomᅟ的获取器。- bottomChanged(bottom)¶
- Parameters:
底部 – int
属性
bottomᅟ的通知信号。属性
bottomᅟ的设置器。- setRange(bottom, top)¶
- Parameters:
bottom – int
top – int
设置验证器的范围,仅接受介于
bottom和top之间的整数(包括这两个值)。属性
topᅟ的设置器。属性
topᅟ的获取器。- topChanged(top)¶
- Parameters:
top – int
属性
topᅟ的通知信号。