pyqt4文档阅读(10.1):QIntValidator-QDoubleValidator-QRegExpValidator
来源:互联网 发布:广电网络倒闭 编辑:程序博客网 时间:2024/06/09 22:22
本系列文章长期更新修改.
QIntValidator,QDoubleValidator,QRegExpValidator,都是继承QValidator的验证器.
QIntValidator和QDoubleValidator分别是整数和浮点数的验证器,而QRegExpValidator则是正则表达式验证器,几乎可实现任何格式的输入验证.
属性:
QIntValidator
Methods
- __init__ (self, QObject parent)
- __init__ (self, int bottom, int top, QObject parent)
- int bottom (self)
- setBottom (self, int)
- setRange (self, int bottom, int top)
- setTop (self, int)
- int top (self)
- (QValidator.State, int) validate (self, QString, int)
QDoubleValidator
Types
- enum Notation { StandardNotation, ScientificNotation }
Methods
- __init__ (self, QObject parent)
- __init__ (self, float bottom, float top, int decimals, QObject parent)
- float bottom (self)
- int decimals (self)
- Notation notation (self)
- setBottom (self, float)
- setDecimals (self, int)
- setNotation (self, Notation)
- setRange (self, float bottom, float top, int decimals = 0)
- setTop (self, float)
- float top (self)
- (QValidator.State, int) validate (self, QString, int)
QRegExpValidator
Methods
- __init__ (self, QObject parent)
- __init__ (self, QRegExp rx, QObject parent)
- QRegExp regExp (self)
- setRegExp (self, QRegExp rx)
- (QValidator.State, int pos) validate (self, QString input, int pos)
详细分析:
1.validate()函数
三种验证器都有一个函数签名一样的validate()函数,该函数的分析参考QValidator篇.
- (QValidator.State, int pos) validate (self, QString input, int pos)
2.基础验证属性
三种验证器有用于验证的基础属性.
其中QIntValidator和QDoubleValidator类似,都有一个上界和下界(闭区间),输入要在上下界之间.但QDoubleValidator多了个小数点位数decimals.
QDoubleValidator在逻辑上使用定点数作为输入.假如小数点位数设置为2,而你输入2.333,QDoubleValidator不会接受这个输入.
而QRegExpValidator则有一个正则表达式,输入要匹配这个表达式.
这些属性都可以在初始化的时候设置,或者之后用get/set函数.
- QIntValidator
- __init__ (self, QObject parent)
- __init__ (self, int bottom, int top, QObject parent)
- int bottom (self)
- setBottom (self, int)
- int top (self)
- setTop (self, int)
- setRange (self, int bottom, int top)
- QDoubleValidator
- __init__ (self, QObject parent)
- __init__ (self, float bottom, float top, int decimals, QObject parent)
- float bottom (self)
- setBottom (self, float)
- float top (self)
- setTop (self, float)
- setRange (self, float bottom, float top, int decimals = 0)
- int decimals (self)
- setDecimals (self, int)
- QRegExpValidator
- __init__ (self, QObject parent)
- __init__ (self, QRegExp rx, QObject parent)
- QRegExp regExp (self)
- setRegExp (self, QRegExp rx)
3.QDoubleValidator的符号类型notation
QDoubleValidator有一个属性notation,会影响validate()函数的结果.
notation是一个枚举量,默认是QDoubleValidator.ScientificNotation
- Notation notation (self)
- setNotation (self, Notation)
而当它是科学计数法的时候,QDoubleValidator无论是0.015或1.5e-2都接受,这里要注意.
4.Intermediate和Invalid
不同验证器对QValidator的两个枚举量Intermediate和Invalid的理解是不同的.
对QIntValidator来说,如果数位太少,则返回Intermediate,数位太多或数字太大则返回Invalid.
比如,range是[100,499],输入50返回Intermediate,输入500返回Invalid.
对QDoubleValidator来说,range要考虑,小数点位数也要考虑.
在允许输入科学计数法的时候,当一个输入的小数点位数超出decimals属性时,如果这个数是标准型,则QDoubleValidator返回Invalid,如果是科学计数法的,则返回Intermediate.
对QRegExpValidator来说,如果输入再补充一些字符就能匹配的话,返回Intermediate,否则返回Invalid.
- pyqt4文档阅读(10.1):QIntValidator-QDoubleValidator-QRegExpValidator
- pyqt4文档阅读(1):QSpinBox
- pyqt4文档阅读(1.1):QDoubleSpinBox
- pyqt4文档阅读(2):QSlider
- pyqt4文档阅读(3):QLCDNumber
- pyqt4文档阅读(4):QPushButton
- pyqt4文档阅读(5):QLineEdit
- pyqt4文档阅读(6):QGridLayout
- pyqt4文档阅读(7):QSize
- pyqt4文档阅读(7.1):QPoint
- pyqt4文档阅读(7.2):QRect
- pyqt4文档阅读(7.4):QLine
- pyqt4文档阅读(7.5):QLineF
- pyqt4文档阅读(8):QComboBox
- pyqt4文档阅读(9):QColor
- pyqt4文档阅读(4.1):QCheckBox
- pyqt4文档阅读(10):QValidator
- pyqt4文档阅读(11):QKeySequence
- Android 踩坑——FloatingActionButton自动添加边距
- 泛型的反射
- 角色和权限Hibernate实体映射配置
- eclipse导入myeclipse项目
- Struts2 <s:token>防止表单重复提交 %{}
- pyqt4文档阅读(10.1):QIntValidator-QDoubleValidator-QRegExpValidator
- J2EE中常见易混淆概念
- 轻松学习java可重入锁(ReentrantLock)的实现原理
- Spring JTA事务配置JOTM
- 递归的几个经典例子
- LinkedList模拟队列和堆栈
- Eclipse去除js错误
- solr查询语法
- Solr API例子详解