QT LineEdit限制输入内容【转】

原文:http://blog.sina.com.cn/s/blog_6e198d4f0100mxbg.html

1。输入int类型

QValidator *validator=new QIntValidator(100,999this);

QLineEdit *edit=new QLineEdit(this);

edit->setValidator(validator);

也可以表示成

 QLineEdit *edit=new QLineEdit(this);

 edit->setValidator(new QIntValidator(100,999,this));

 

2.输入double类型

QLineEdit *edit=new QLineEdit(this);

edit->setValidator(new QDoubleValidator(double bottom,double top,,int decimalthis));

 

 bottom为最小范围,top为最大范围,decimal为精确度,精确到第几位小数。

3。输入任意匹配类型

QRegExp regExp(“[A-Za-z][1-9][0-9]{0,2}”);//正则表达式,第一位数字为a-z的数字,第二位为1-9的数字,后边是0-2位0-9的数字

lineEdit->setValidator(new QRegExpValidator(regxp,this));

 

 

posted @ 2013-10-12 17:16  Leo Forest  阅读(1822)  评论(0编辑  收藏  举报