当前位置:网站首页>QLineEdit学习与使用
QLineEdit学习与使用
2022-08-01 17:33:00 【小小工程员】
QLineEdit
| 方法 | 描述 | 备注 |
|---|---|---|
| setText() | 设置文本 | 设置文本,槽函数,不发信号 |
| text() | 获取文本 | |
| setPlaceholderText() | 设置提示文字 | |
| setClearButtonEnabled() | 设置清空文字 | 在输入文本后右侧显示一个清空按钮可以清空输入 |
| setReadOnly() | 设置只读 | 可区分不同人(状态时)的权限 |
| setMaxLength() | 设置可输入的字节长度 | 如输入密码是最高可输入8位,不管是中文还是应为都是按一个位数 |
| setEchoMode() | 设置显示模式 | setEchoMode(QLineEdit::Normal) |


掩码格式


信号触发


显示模式




查看样式表帮助文档


参考代码
//setText()
ui.lineEdit->setText("lineedit test");
ui.label->setText(QString::fromLocal8Bit("邮箱格式不正确!"));
//text()
QString txt = ui.lineEdit->text();
txt += " ";
txt += ui.textEdit->text();
ui.label->setText(txt);
//setPlaceholderText()
ui.lineEdit->setPlaceholderText(QString::fromLocal8Bit("提示输入"));
//掩码输入
ui.lineEdit->setInputMask("000.000.000.000;_"); //当前面没有输入时,用_进行填充;0格式输入:只允许输入数字,但非必须
//即当用户按下回车键后,不管输入多少个数字,都会激发returnPressed信号。
ui.textEdit->setInputMask("AAAAA;_"); //A:只允许输入字母,且必须:必须输入5个字符型数据,才会激发returnPressed信号。
//输入验证设置
//整数验证
QIntValidator *ival = new QIntValidator();
ival->setRange(1, 1000);
ui.iedit->setValidator(ival); //设置可输入有效范围,Int整数,范围1-1000。
//浮点数验证
QDoubleValidator *dval = new QDoubleValidator();
dval->setRange(-100, 10000,3); //浮点型,范围-100 ~ 10000 ,精度为小数点后3位
//不用科学计数法 :浮点型,输入完整才会验证,所以导致浮点设置范围无效了。
dval->setNotation(QDoubleValidator::StandardNotation);
ui.dedit->setValidator(dval);
//验证邮箱 [email protected]
QRegExp exp("[a-zA-Z0-9-_][email protected][a-zA-Z0-9-_]+\\.[a-zA-Z]+"); //[a-zA-Z0-9-_]:a-z、A-Z、0-9、-和_都可以匹配。
//+:表示前面的在范围内的字符至少出现一次,(*号表示可以出现多次,或者不出现)
// \\. 表示的是\进行转义\\,再加.(由于单独的.在正则表达式中是有意义的,故而需要转义),最后的结果就是显示一个小数点.
QRegExpValidator *rval = new QRegExpValidator(exp);
ui.email->setValidator(rval);
//验证邮箱输入正确与否
//格式不正确提示
const QValidator *v = ui.email->validator(); //获取验证格式
int pos = 0; //出现验证错误的位置。
/* 返回 enum State { Invalid, 不正确 Intermediate, 中间状态,没输入结束:如 [email protected] Acceptable 格式正确 };*/
if (v->validate(ui.email->text(), pos) != QValidator::Acceptable)
{
ui.label->setText(QString::fromLocal8Bit("邮箱格式不正确!"));
}
边栏推荐
猜你喜欢

QT基础功能,信号、槽
![[Dark Horse Morning Post] Hu Jun's endorsement of Wukong's financial management is suspected of fraud, which is suspected to involve 39 billion yuan; Fuling mustard responded that mustard ate toenails](/img/d7/4671b5a74317a8f87ffd36be2b34e1.jpg)
[Dark Horse Morning Post] Hu Jun's endorsement of Wukong's financial management is suspected of fraud, which is suspected to involve 39 billion yuan; Fuling mustard responded that mustard ate toenails

2022年SQL大厂高频实战面试题(详细解析)

The site is not found after the website is filed. You have not bound this domain name or IP to the corresponding site! The configuration file does not take effect!

04 flink cluster construction

金仓数据库 KingbaseES V8.3 至 V8.6 迁移最佳实践(4. V8.3 到 V8.6 数据库移植实战)

Complete knapsack problem to find the number of combinations and permutations

TCP百万并发服务器优化调参

后台管理系统的权限思路

MySql 怎么查出符合条件的最新的数据行?
随机推荐
Daily Yuxian Big Defeat
M1芯片电脑安装cerebro
The anxiety of the post-90s was cured by the vegetable market
深入分析类加载器
生物制药产业发展现状和趋势展望
【TDP加码福利】COS用户实践征文月,等你来投稿!!!
素域和扩域
The site is not found after the website is filed. You have not bound this domain name or IP to the corresponding site! The configuration file does not take effect!
【二叉树】奇偶树
指针和解引用
程序员架构修炼之道:如何设计“易理解”的系统架构?
SQL函数 TO_CHAR(三)
云商店携手快报税,解锁财务服务新体验!
【R语言】批量重命名文件
后台管理系统的权限思路
完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?
研发团队数字化转型实践
关于LocalDateTime的全局返回时间带“T“的时间格式处理
QT_事件类
食品安全 | 新鲜食品vs速食食品,哪一种是你的菜?