Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt QLineEdit仅接受一个字符/数字_Qt_Qlineedit - Fatal编程技术网

Qt QLineEdit仅接受一个字符/数字

Qt QLineEdit仅接受一个字符/数字,qt,qlineedit,Qt,Qlineedit,我想要一个只接受字符或数字的QLineEdit。是否可以将其设置为html中的输入,使其具有maxlength?我的意思是从QLineEdit的构造函数中执行此操作 我不需要复杂的东西 我不需要复杂的东西 不幸的是,这不能称之为简单的解决方案,但你应该得到建议 用法示例: #include <QRegExpValidaor> #include <QLineEdit> ... ... QRegExp rx ("\\w"); QRegExpValidator * v = ne

我想要一个只接受字符或数字的
QLineEdit
。是否可以将其设置为html中的输入,使其具有
maxlength
?我的意思是从
QLineEdit
的构造函数中执行此操作

我不需要复杂的东西

我不需要复杂的东西

不幸的是,这不能称之为简单的解决方案,但你应该得到建议

用法示例:

#include <QRegExpValidaor>
#include <QLineEdit>
...
...
QRegExp rx ("\\w");
QRegExpValidator * v = new QRegExpValidator (rx, this);
QLineEdit * le = new QLineEdit (this);
le->setValidator (v);
#包括
#包括
...
...
QRegExp rx(“\\w”);
QRegExpValidator*v=新的QRegExpValidator(rx,this);
QLineEdit*le=新的QLineEdit(此);
le->setValidator(v);

以下是将行编辑输入限制为一个字符/数字的另一种方法:

QLineEdit le;
le.setInputMask("N");
le.show();

有关输入掩码用法的更多详细信息,请参阅。

一切都与您希望的完全一样
QLineEdit
具有
maxLength
属性。可以使用属性系统或setter方法进行设置:

QLineEdit le;
le.setMaxLength(1);

就这样。

我希望有一种方法可以减少QLineEdit中的写入空间。。。它看起来更优雅。我对Qt不是很熟悉,所以可能存在更优雅的方式。谢谢你的使用示例!如果我找不到别的办法,我就用它。没门!非常感谢!:)