当前位置:网站首页>Qt QLineEdit详解
Qt QLineEdit详解
2022-06-29 06:37:00 【Mr.codeee】
1.概述
QLineEdit 行编辑框允许用户使用一组有用的编辑功能输入和编辑一行纯文本,包括撤消和重做、剪切和粘贴以及拖放。
2.常用数据接口
2.1设置/获取 显示数据
void setText(const QString &)
QString text() const
2.2设置只读
void setReadOnly(bool)
2.3设置文本边距
void setTextMargins(int left, int top, int right, int bottom)
2.4设置提示文本
当没有输入数据时,会显示提示文字,比如:请输入密码 之类的。
void setPlaceholderText(const QString &)2.5设置文本最大长度
void setMaxLength(int)
2.6设置对齐方式,居中、左、右等
void setAlignment(Qt::Alignment flag)
2.7对输入的文本进行限制,可以使用正则表达式,比如:只能输入数字、英文字母。
void setValidator(const QValidator *v)
2.8设置显示模式,比如:密码显示用 黑圈 代替。
void setEchoMode(EchoMode)
2.9设置掩码,比如:设置ip地址
void setInputMask(const QString &inputMask)
3.常用信号
当按下Return或Enter键或行编辑失去焦点时,会发出此信号
void editingFinished()
每当文本发生变化时,就会发出这个信号。text参数是新的text。
void textChanged(const QString &text)
4.示例
一个简单的例子

源码
#include "widget.h"
#include "ui_widget.h"
#include <QValidator>
#include <QDebug>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->leUserName->setPlaceholderText("请输入用户名");
//设置居中
ui->leUserName->setAlignment(Qt::AlignCenter);
ui->lePasswd->setPlaceholderText("请输入密码");
//设置密码模式显示
ui->lePasswd->setEchoMode(QLineEdit::Password);
//设置只能输入数字 正则表达式
QRegExpValidator *pRevalidotor = new QRegExpValidator(QRegExp("[0-9]{20}"), this);
ui->leIp->setValidator(pRevalidotor);
ui->leIp->setInputMask("000.000.000.000");
}
Widget::~Widget()
{
delete ui;
}
//简单响应一下信号改变
void Widget::on_leUserName_textChanged(const QString &arg1)
{
qDebug()<<arg1;
}
5.一个常见问题
QLineEdit设置QValidator之后,信号不能正常连接的情况。
边栏推荐
- IDEA常用插件
- Presto-Trial
- RedisTemplate处理hash整数类型的问题解析
- 配置Flutter开发环境
- 分享 10 个 JS Promise 相关的面试题
- Where is the Gcov symbol- Where are the gcov symbols?
- [C language] flexible array
- What is 'EC2-Other' filter in 'Cost Explorer' dashboard mean? [closed]
- How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]
- Difference between static and final
猜你喜欢

MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory

MySQL learning notes

Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future

How to change the password after forgetting the MySQL password (the latest version of 2022 detailed tutorial nanny level)

Configuring the flutter development environment

Sourcetree remote red exclamation point

What are the uses of wireless pressure collectors?

As a qualified network worker, you must master DHCP snooping knowledge!

2022.02.15 - 240. Lucky number in matrix

Why are keys unordered in golang map
随机推荐
Object detection - VIDEO reasoning using yolov6
Monitor employee turnover dynamics. This system makes employees tremble!
Configuring the flutter development environment
Fresnel diffraction with rectangular aperture based on MATLAB
Teach you how to develop your own NPM package (publish to the NPM official website)
开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
How to fix Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorli
package.json的所有配置项及其用法,你都熟悉么
Fault: KDC warning log for id29
How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]
mongostat性能分析
QT (x): innosetup for software packaging
QT (x): packaging and deployment
Redistemplate handles hash integer type problem resolution
想请教一下,究竟有哪些劵商推荐?在线开户是安全么?
Sourcetree remote red exclamation point
Chapter IV introduction to FPGA development platform
National Defense University project summary
融入STEAM教育的劳动技能课程
Labor skills courses integrated into steam Education