当前位置:网站首页>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("邮箱格式不正确!"));
}
边栏推荐
猜你喜欢
随机推荐
QT_QThread线程
GRUB2的零日漏洞补丁现已推出
星途一直缺颠覆性产品?青岛工厂这款M38T,会是个突破点?
在码云拉取代码后,调整了seata版本1.5.2。出现如下异常。是因为数据库表缺少字段导致的吗?
TCP million concurrent server optimization parameters
ROS2系列知识(7):用rqt_console查看日志logs
RecSys'22|CARCA:交叉注意力感知上下文和属性进行推荐
千万级乘客排队系统重构&压测方案总结篇
GTK修改pixmap像素,提取pixmap像素RGB值
My new book has sold 10,000 copies!
B002 - 基于嵌入式的老人定位追踪监测仪
金仓数据库KingbaseES安全指南--6.4. RADIUS身份验证
成为优秀架构师必备技能:怎样才能画出让所有人赞不绝口的系统架构图?秘诀是什么?快来打开这篇文章看看吧!...
【100个网络运维工作者必须知道的小知识!】
史上最全的Redis基础+进阶项目实战总结笔记
浅谈大数据背景下数据库安全保障体系
M1芯片电脑安装cerebro
云商店携手快报税,解锁财务服务新体验!
金仓数据库 KDTS 迁移工具使用指南(2. 简介)
[ACNOI2022]物品









