Qt之QLineEdit
2017-06-04 15:38
274 查看
QLineEdit
setMode() //设置文本编辑显示模式
enum EchoMode:
Normal //普通模式
NoEcho //不允许输入
Password //编辑及显示时为密码样式
PasswordEchoOnEdit //显示时为密码样式
setInputMask() // 设置输入掩码来限制输入字符
setValidator() // 为其设置验证器(validator)来验证输入
setCompleter() // 为其设置自动完成器
setMode() //设置文本编辑显示模式
enum EchoMode:
Normal //普通模式
NoEcho //不允许输入
Password //编辑及显示时为密码样式
PasswordEchoOnEdit //显示时为密码样式
setInputMask() // 设置输入掩码来限制输入字符
setValidator() // 为其设置验证器(validator)来验证输入
setCompleter() // 为其设置自动完成器
#include "widget.h" #include <QLabel> #include <QLineEdit> #include <QHBoxLayout> #include <QVBoxLayout> #include <QValidator> #include <QRegExp> #include <QCompleter> // QLineEdit // setMode() //设置文本编辑显示模式 // enum EchoMode: // Normal //普通模式 // NoEcho //不允许输入 // Password //编辑及显示时为密码样式 // PasswordEchoOnEdit //显示时为密码样式 // setInputMask() // 设置输入掩码来限制输入字符 // setValidator() // 为其设置验证器(validator)来验证输入 // setCompleter() // 为其设置自动完成器 QHBoxLayout* getlayout(QWidget*,QWidget*); Widget::Widget(QWidget *parent) : QWidget(parent) { resize(300,300); QLabel *la1 = new QLabel("显示模式:"); QLineEdit *ld1 = new QLineEdit; QLabel *la2 = new QLabel("输入掩码:"); QLineEdit *ld2 = new QLineEdit; QLabel *la3 = new QLabel("输入验证:"); QLineEdit *ld3 = new QLineEdit; QLabel *la4 = new QLabel("自动完成:"); QLineEdit *ld4 = new QLineEdit; QHBoxLayout *ret1 = getlayout(la1,ld1); QHBoxLayout *ret2 = getlayout(la2,ld2); QHBoxLayout *ret3 = getlayout(la3,ld3); QHBoxLayout *ret4 = getlayout(la4,ld4); QVBoxLayout *mainlayout = new QVBoxLayout; mainlayout->addLayout(ret1); mainlayout->addLayout(ret2); mainlayout->addLayout(ret3); mainlayout->addLayout(ret4); setLayout(mainlayout); //显示模式 ld1->setEchoMode(QLineEdit::PasswordEchoOnEdit); //输入掩码 ld2->setInputMask("D99999999D");//输入前后不能为0的十位数 //输入验证 QRegExp rgx("\\d{11}");//输入十一位数 运用正则表达式 QValidator *validator = new QRegExpValidator(rgx,this); ld3->setValidator(validator); //自动验证 QStringList words; words << "math" << "macro" << "monther"; QCompleter *completer = new QCompleter(words,this); completer->setCaseSensitivity(Qt::CaseInsensitive);//大小写不敏感 ld4->setCompleter(completer); } QHBoxLayout* getlayout(QWidget* w1,QWidget *w2) { QHBoxLayout *ret = new QHBoxLayout; ret->addStretch(); ret->addWidget(w1); ret->addSpacing(10); ret->addWidget(w2); ret->addStretch(); return ret; }
相关文章推荐
- 用QT实现的用于显示输入IP的LineEdit控件
- qt中的lineEdit文本输入框的输入类型限制(三种验证类)
- qt 两个lineEdit 判断焦点问题
- Qt之QLineEdit之插入图标及位置设置
- Qt中lineedit的输入与输出
- qt 自定义 lineedit
- qt中lineedit的几个属性设置
- Qt的LineEdit 输入内容控制
- Qt之QLineEdit之透明设置
- QT 的 lineEdit的textChanged(const QString &)信号被触发两次的原因
- [转]qt 自动完成LineEdit
- 1./** */等记录;2.tableview的item当控件;3.;4.lineedit下划线;android for qt out of memory;
- QT按键背景图片 LineEdit Label网络
- qt中的lineEdit文本输入框的输入类型限制(三种验证类)
- topic5:Qt入门之常用qt控件认知之QLineEdit
- qt中的lineEdit文本输入框的输入类型限制(三种验证类)
- QT 常用部件 (四)自动完成LineEdit
- QT中LineEdit怎么设置不显示明文
- qt学习笔记之QLineEdit
- QT问题系列(4) - qtcreator提示lineEdit was not declared in the scope