当前位置: 首页 > article >正文

9_3_LineEdit

LineEdit

InputMask 版本

//核心属性
inputMask()//输⼊内容格式约束,参数"000",输入内容就限制只能输入三个数字
echoMode()//显⽰⽅式.参数有QLineEdit::Normal、QLineEdit::Password、QLineEdit::NoEcho
placeHolderText()//当输⼊框内容为空的时候, 显⽰什么样的提⽰信息,参数是字符串
clearButtonEnabled()//是否会⾃动显⽰出 "清除按钮,参数是布尔类型。
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //初始化第一个编译框,给它加上默认的提示语和一键清除按键
    ui->lineEdit_name->setPlaceholderText("请输入名称");
    ui->lineEdit_name->setClearButtonEnabled(true);

    //初始化第二个编译框,给它加上默认的提示语和一键清除按键,给密码装上保护措施
    ui->lineEdit_password->setPlaceholderText("请输入名称");
    ui->lineEdit_password->setClearButtonEnabled(true);
    ui->lineEdit_password->setEchoMode(QLineEdit::Password);

    //初始化性别
    ui->radioButton_male->setChecked(true);

    //初始化第三个
    ui->lineEdit_phoneNumber->setPlaceholderText("请输入电话");
    ui->lineEdit_phoneNumber->setClearButtonEnabled(true);
    ui->lineEdit_phoneNumber->setInputMask("00000000000");

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QString gender = ui->radioButton_male->isEnabled()?"男":"女";
    qDebug()<< "姓名:"<<ui->lineEdit_name->text()
            <<"密码:"<<ui->lineEdit_password->text()
           <<"性别:"<<gender
          <<"手机号"<<ui->lineEdit_phoneNumber->text();
}

正则表达式版本

正则表达式:QRegExp (Regular Express)

	//设置正则表达式,设置正则表达式需要的验证器
	QRegExp regExp("^1\\d{10}$");
    //需要给单行输入框设置一个验证器,这样下面才能对输入框中的文本进行验证
    ui->lineEdit->setValidator(new QRegExpValidator(regExp));
	//validate有两个返回值,一个是acceptable,一个是invalid,还一个忘了,参数是字符串和整形数字,整形没意义。
	


	Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->pushButton->setEnabled(false);

    QRegExp regExp("^1\\d{10}$");
    //需要给单行输入框设置一个验证器,这样下面才能对输入框中的文本进行验证
    ui->lineEdit->setValidator(new QRegExpValidator(regExp));
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_lineEdit_textEdited(const QString &text)
{
    QString string = text;
    int pos = 0;
    if(ui->lineEdit->validator()->validate(string, pos) == QRegExpValidator::Acceptable)
    {
        ui->pushButton->setEnabled(true);
    }
    else
    {
         ui->pushButton->setEnabled(false);
    }
}

对比两个密码

//判断字符串是否为空字符串,返回值是个布尔类型的
isEmpty();

void Widget::on_lineEdit_textEdited(const QString &arg1)
{
    (void) arg1;
    compare();
}

void Widget::compare()
{
    const QString t1 = ui->lineEdit->text();
    const QString t2 = ui->lineEdit_2->text();
    if(t1.isEmpty() && t2.isEmpty())
    {
        ui->label->setText("密码为空");
    }
    else if(t1 == t2)
    {
        ui->label->setText("密码一致");
    }
    else
    {
        ui->label->setText("密码不一致");
    }
}


void Widget::on_lineEdit_2_textEdited(const QString &arg1)
{
    (void) arg1;
    compare();
}

显示密码

插入个屁
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->label->setText("请输入密码");
    ui->lineEdit->setPlaceholderText("第一次输入密码");
    ui->lineEdit_2->setPlaceholderText("第二次输入密码");

    ui->lineEdit->setEchoMode(QLineEdit::Password);
    ui->lineEdit_2->setEchoMode(QLineEdit::Password);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_lineEdit_textEdited(const QString &arg1)
{
    (void) arg1;
    compare();
}

void Widget::compare()
{
    const QString t1 = ui->lineEdit->text();
    const QString t2 = ui->lineEdit_2->text();
    if(t1.isEmpty() && t2.isEmpty())
    {
        ui->label->setText("密码为空");
    }
    else if(t1 == t2)
    {
        ui->label->setText("密码一致");
    }
    else
    {
        ui->label->setText("密码不一致");
    }
}


void Widget::on_lineEdit_2_textEdited(const QString &arg1)
{
    (void) arg1;
    compare();
}

void Widget::on_checkBox_1_toggled(bool checked)
{
    if(checked)
    {
        ui->lineEdit->setEchoMode(QLineEdit::Normal);
    }
    else{
         ui->lineEdit->setEchoMode(QLineEdit::Password);
    }
}

void Widget::on_checkBox_2_toggled(bool checked)
{
    if(checked)
    {
        ui->lineEdit->setEchoMode(QLineEdit::Normal);
    }
    else{
         ui->lineEdit->setEchoMode(QLineEdit::Password);
    }
}


http://www.kler.cn/news/288708.html

相关文章:

  • 抓取海外电商平台数据时,是否最好使用当地的IP?
  • 基础闯关4
  • 数学建模常用工具总结
  • 关于Linux(CentOS 7)中的用户sudo命令
  • 知识付费小程序搭建:开启知识变现新时代
  • 采用SIP封装的传感器系列:ARS19510LUBBTN、A19520LUBBTN、A1696PKHTN、A1694PKLN-RNZBE(资料)
  • Learning——protobuf的下载
  • 【Springboot服务实现类】用户登录逻辑梳理(未完待续)
  • 【管理型文档】软件需求管理过程(原件)
  • 使用 ip route 命令配置 Linux 路由表的详细指南
  • AI BT人工智能交互平台应用程序重磅上线,开启全球数字革命
  • 探索 HarmonyOS NEXT Developer Beta6,开启创新应用
  • 钢铁百科:NM360钢板材质、NM360机械性能、NM360韧性焊接性能
  • 多场景建模: STAR(Star Topology Adaptive Recommender)
  • 鸢尾花书实践和知识记录[数学要素3-1万物皆数]
  • python-pdf文件加密和解密
  • 评价决策类——层次分析法+数学建模+实战分析
  • spring -- AOP详解
  • QT教程-十六,QT中如何解析JSON
  • Java注解基础入门
  • LiveQing视频点播流媒体RTMP推流服务功能-支持OBS推流摄像机RTMP推流支持无人机RTMP推流解决大疆无人机推流花屏问题完美解决大疆无人机花屏
  • Postgresql表和索引占用空间回收释放(表空间膨胀)
  • NTFS安全权限和文件共享
  • Ajax的$.post(),$.get(),$.ajax 方法请求都是默认异步请求
  • Python | Leetcode Python题解之第390题消除游戏
  • 3D Tiles的4x4的仿射变换矩阵
  • 计算机网络——ARP篇
  • 向沐神学习笔记:GPT,GPT-2,GPT-3 论文精读【论文精读】GPT部分
  • 4G手机智能遥控开关
  • Oracle查询预防解决分母为0的方法