当前位置:网站首页>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("邮箱格式不正确!"));
}
边栏推荐
猜你喜欢

C语言:表达式求值详解

计算IoU(D2L)

B005 – 基于STC8的单片机智能路灯控制系统

深入分析类加载器

SQL的索引详细介绍

助推科技强国高质量发展《科创超级训练营》系列活动正式拉开帷幕

How can become a good architect necessary skills: painting for all the people praise the system architecture diagram?What is the secret?Quick to open this article and have a look!.

zabbix部署和简单使用

ROS2支持技术:DDS简述

C# LibUsbDotNet 在USB-CDC设备的上位机应用
随机推荐
Are online account opening commissions reliable? Is online account opening safe?
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!
下载 | 谷歌科学家Kevin P. Murphy发布新书《概率机器学习:高级主题》
吴恩达机器学习课后习题——kmeans
opencv实时人脸检测
关于LocalDateTime的全局返回时间带“T“的时间格式处理
[供应链·案例篇]石油和天然气行业的数字化转型用例
使用设备树时对应的驱动编程
ROS2系列知识(5):【参数】如何管理?
SQL窗口函数
银行案例|Zabbix跨版本升级指南,4.2-6.0不香吗?
JumpServer堡垒机部署
SQL的索引详细介绍
我在启牛开户安全吗?谁能告诉我开不靠谱?
史上最全的Redis基础+进阶项目实战总结笔记
表达式;运算符,算子;取余计算;运算符优先顺序
金仓数据库 OCCI迁移指南(3. KingbaseES的OCCI特性支持)
主流小程序框架性能分析
2022年深圳市促进大健康产业集群高质量发展的若干措施
golang json 返回空值