首页 > 其他 > 详细

PyQt4学习--QLineEdit加入正则判断IP

时间:2014-03-14 18:31:03      阅读:748      评论:0      收藏:0      [点我收藏+]

用到了:

QtCore.QRegExp类--------------正则表达式

QtGui.QRegExpValidator类------做验证

setValidator方法

bubuko.com,布布扣
# !usr/bin/python 
# _*_ coding: utf-8 _*_

from PyQt4 import QtGui, QtCore
class MyQDialog(QtGui.QDialog):
    """
    Class documentation goes here.
    """
    def __init__(self, parent = None):
        """
        Constructor
        """
        QtGui.QDialog.__init__(self, parent)
        self.resize(200, 60)
        self.setWindowTitle(u"QLineEdit加正则")
        
        regExp=QtCore.QRegExp(^((2[0-4]\d|25[0-5]|[1-9]?\d|1\d{2})\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?):\d{1,5}$) 
        
        self.IP_edit = QtGui.QLineEdit("",self)
        self.IP_edit.setValidator(QtGui.QRegExpValidator(regExp,self))
        self.IP_edit.setGeometry(QtCore.QRect(10, 20, 180, 25))

    
if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    ui=MyQDialog()
    ui.show()
    app.exec_()
bubuko.com,布布扣

PyQt4学习--QLineEdit加入正则判断IP,布布扣,bubuko.com

PyQt4学习--QLineEdit加入正则判断IP

原文:http://www.cnblogs.com/luobuda/p/PyQt4_002.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!