• 19231阅读
  • 3回复

怎么限制QLineEdit输入字符串的长度? [复制链接]

上一主题 下一主题
离线jun11202006
 
只看楼主 倒序阅读 楼主  发表于: 2009-08-13
  请教各位高手,怎么限制QLineEdit中输入字符串的长度?
积极交流共同进步!
离线dbzhang800

只看该作者 1楼 发表于: 2009-08-13
不妨好好看手册:

maxLength : int

This property holds the maximum permitted length of the text.

If the text is too long, it is truncated at the limit.

If truncation occurs any selected text will be unselected, the cursor position is set to 0 and the first part of the string is shown.

If the line edit has an input mask, the mask defines the maximum string length.

By default, this property contains a value of 32767.

Access functions:

int maxLength () const
void setMaxLength ( int )
离线jun11202006
只看该作者 2楼 发表于: 2009-08-14
谢谢!已经解决!
积极交流共同进步!

只看该作者 3楼 发表于: 2011-08-17
phoneNumEdit = new QLineEdit();
    phoneNumEdit->setToolTip(QObject::trUtf8("仅限数字"));
    QRegExp regx("[0-9]+$");
    QValidator *validator = new QRegExpValidator(regx, phoneNumEdit);
    phoneNumEdit->setMaxLength(11);
    phoneNumEdit->setValidator(validator);

以上实现编辑框中只能输入数字并且只能输入11位
快速回复
限100 字节
 
上一个 下一个