当前位置:网站首页>QLineEdit learning and use
QLineEdit learning and use
2022-08-01 17:40:00 【little engineer】
QLineEdit
| 方法 | 描述 | 备注 |
|---|---|---|
| setText() | 设置文本 | 设置文本,槽函数,不发信号 |
| text() | 获取文本 | |
| setPlaceholderText() | 设置提示文字 | |
| setClearButtonEnabled() | Set clear text | Displays a clear button on the right after entering text to clear the input |
| setReadOnly() | 设置只读 | distinguish different people(状态时)的权限 |
| setMaxLength() | Set the length of bytes that can be entered | If the input password is the highest8位,Whether it is Chinese or should be based on one digit |
| setEchoMode() | 设置显示模式 | setEchoMode(QLineEdit::Normal) |


掩码格式


信号触发


显示模式




Check out the stylesheet help documentation


参考代码
//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;_"); //When there is no previous input,用_进行填充;0格式输入:只允许输入数字,但非必须
//When the user presses the enter key,No matter how many numbers are entered,都会激发returnPressed信号.
ui.textEdit->setInputMask("AAAAA;_"); //A:只允许输入字母,且必须:必须输入5个字符型数据,才会激发returnPressed信号.
//Enter verification settings
//整数验证
QIntValidator *ival = new QIntValidator();
ival->setRange(1, 1000);
ui.iedit->setValidator(ival); //Set the input valid range,Int整数,范围1-1000.
//浮点数验证
QDoubleValidator *dval = new QDoubleValidator();
dval->setRange(-100, 10000,3); //浮点型,范围-100 ~ 10000 ,精度为小数点后3位
//no scientific notation :浮点型,Enter complete to verify,So the floating point setting range is invalid..
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、-和_都可以匹配.
//+:Indicates that the preceding character in the range occurs at least once,(*sign indicates that it can appear multiple times,或者不出现)
// \\. 表示的是\进行转义\\,再加.(由于单独的.is meaningful in regular expressions,therefore need to be escaped),The final result is to display a decimal point.
QRegExpValidator *rval = new QRegExpValidator(exp);
ui.email->setValidator(rval);
//Verify that the email is entered correctly
//Incorrect format prompt
const QValidator *v = ui.email->validator(); //get validation format
int pos = 0; //Where the validation error occurred.
/* 返回 enum State { Invalid, 不正确 Intermediate, 中间状态,End without input:如 [email protected] Acceptable 格式正确 };*/
if (v->validate(ui.email->text(), pos) != QValidator::Acceptable)
{
ui.label->setText(QString::fromLocal8Bit("邮箱格式不正确!"));
}
边栏推荐
- 金仓数据库 OCCI迁移指南(3. KingbaseES的OCCI特性支持)
- AIOps智能运维的领跑者擎创科技正式入驻InfoQ 写作社区!
- TCP百万并发服务器优化调参
- SRM供应商管理系统如何助力口腔护理企业实现采购战略的转型升级
- 吴恩达机器学习课后习题——kmeans
- Basic image processing in opencv
- OpenCV安装、QT、VS配置项目设置
- 关于LocalDateTime的全局返回时间带“T“的时间格式处理
- B002 - Embedded Elderly Positioning Tracking Monitor
- RecSys'22|CARCA:交叉注意力感知上下文和属性进行推荐
猜你喜欢

金仓数据库KingbaseES安全指南--6.3. Kerberos身份验证

JumpServer堡垒机部署

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

Shell nl命令详解(显示行号、读取文件)

参观首钢园

下载 | 谷歌科学家Kevin P. Murphy发布新书《概率机器学习:高级主题》

LeaRun.net快速开发动态表单

My new book has sold 10,000 copies!

ROS2系列知识(7):用rqt_console查看日志logs

RecSys'22|CARCA:交叉注意力感知上下文和属性进行推荐
随机推荐
面经汇总-社招-6年
TCP million concurrent server optimization parameters
统信软件、龙芯中科等四家企业共同发布《数字办公安全创新方案》
opencv real-time face detection
在码云拉取代码后,调整了seata版本1.5.2。出现如下异常。是因为数据库表缺少字段导致的吗?
Xingtu has been short of disruptive products?Will this M38T from the Qingdao factory be a breakthrough?
小贝拉机器人是朋友_普渡科技召开新品发布会,新一代送餐机器人“贝拉”温暖登场...
ROS2系列知识(6):Action服务概念
ROS2支持技术:DDS简述
缓存一致性MESI与内存屏障
【二叉树】奇偶树
二分练习题
2022年MySQL最新面试题
力扣每日一题-第45天-697. 数组的度
B011 - 51-based multifunctional fingerprint smart lock
素域和扩域
04 flink cluster construction
EpiSci|片上系统的深度强化学习:神话与现实
金仓数据库 MySQL 至 KingbaseES 迁移最佳实践(2. 概述)
想做期货,农产品期货怎么炒?波动大么