Chinaunix首页 | 论坛 | 博客
  • 博客访问: 533858
  • 博文数量: 67
  • 博客积分: 1625
  • 博客等级: 上尉
  • 技术积分: 1053
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-04 14:40
文章分类

全部博文(67)

文章存档

2012年(67)

分类: 嵌入式

2012-08-28 21:36:19


  1. import QtQuick 1.1

  2. Rectangle {
  3.     width: 360
  4.     height: 360
  5.     TextInput {
  6.         anchors.centerIn: parent
  7.         text:"1"
  8.         validator: RegExpValidator{regExp: /[0-5][0-9][0-5][.][0-9]/}
  9.     }
  10. }
这样可以限制输入……
第一个数为:0-5
第二个数为:0-9
第三个数为:0-5
第四个数为:.
第五个数为:0-9

同样也可以输入限制字符串:
  1. validator: RegExpValidator{regExp: /love/}
如果要用于限制数大小我认为还是DoubleValidator更实际一点:

  1. validator: DoubleValidator{id: intval; decimals: 1; bottom: 380; top: 500; notation:DoubleValidator.StandardNotation}
结果是:输入在380-500,小数位:1;
==========================================================================
2012年8月30日19:41:32 更新

  1. validator: RegExpValidator{regExp: /^[1-9]{1,2}$/}
结果是只能输入:1-99,具体的含义:[1-9]每位范围1-9;{1,2}位数1-2(总共2位);

  1. validator: RegExpValidator{regExp:/(^[0-9]([.][0-9]{1,2})?$)|(^1[0-9]([.][0-9]{1,2})?$)|(^2[0-3]([.][0-9]{1,2})?$)|(^24([.]0{1,2})?$)/}
结果是只能输入:1-24,允许有一位小数;
阅读(10871) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~