Qt QLineEdit 限制输入类型以及大小Int 和double

http://blog.csdn.net/a_sungirl/article/details/17373405


1.QLineEdit 限制整数

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. m_LineEditIterate = new QLineEdit();  
  2. m_LineEditIterate->setFixedWidth(100);  
  3. m_LineEditIterate->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);  
  4. m_LineEditIterate->setText("2");  
  5. m_LineEditIterate->setValidator(new QIntValidator(1, 9, m_LineEditIterate));  
2. QLieEdit限制double类型,以及小数点,{0,2}这个是控制位数,

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. QRegExp double_rx100("100|([0-9]{0,2}[\.][0-9]{1,3})");   
  2. QRegExp double_rx10000("10000|([0-9]{0,4}[\.][0-9]{1,3})");   
  3. QRegExp double_rx10("10|([0-9]{0,1}[\.][0-9]{1,3})");   
  4. m_LineEditDensity = new QLineEdit;  
  5. m_LineEditDensity->setValidator(new QRegExpValidator(double_rx100, m_LineEditDensity));  
  6. m_LineEditParA = new QLineEdit;  
  7. m_LineEditParA->setValidator(new QRegExpValidator(double_rx10000, m_LineEditParA));  
  8. m_LineEditParB = new QLineEdit;  
  9. m_LineEditParB->setValidator(new QRegExpValidator(double_rx10, m_LineEditParB));  
3.QLineEdit只输入字母和数字 收藏

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. QRegExp regx("[a-zA-Z0-9]+$");  
  2. QValidator *validator = new QRegExpValidator(regx, lined );  
  3. lined->setValidator( validator );  

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值