当前位置:网站首页>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("邮箱格式不正确!"));
}
边栏推荐
- 二分练习题
- zabbix部署和简单使用
- SQL函数 TO_CHAR(三)
- 夸克网盘资源站
- SQL的ROUND函数用法及其实例
- 【二叉树】奇偶树
- 关系运算符和if,else语句
- 【报错】Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘concat‘)
- My new book has sold 10,000 copies!
- 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!
猜你喜欢
随机推荐
关于MySql中explain结果filtered的理解
在码云拉取代码后,调整了seata版本1.5.2。出现如下异常。是因为数据库表缺少字段导致的吗?
研发团队数字化转型实践
棕榈油罐区数字化转型
面经汇总-社招-6年
金仓数据库 KingbaseES V8.3 至 V8.6 迁移最佳实践(4. V8.3 到 V8.6 数据库移植实战)
存储日报-数据湖架构权威指南(使用 Iceberg 和 MinIO)
生物制药产业发展现状和趋势展望
星途一直缺颠覆性产品?青岛工厂这款M38T,会是个突破点?
开发工具:第五章:使用idea生成实体类
QPalette调色板、框架色彩填充
实现mnist手写数字识别
md5sum源码 可多平台编译
个人日记
When custom annotations implement log printing, specific fields are blocked from printing
极化微波成像概述3
关于2022年深圳市福田区支持高端服务业发展项目的申报通知
ROS2系列知识(7):用rqt_console查看日志logs
使用设备树时对应的驱动编程
tooltip 控件