Qt之QLineEdit

QLineEdit
setMode() //设置文本编辑显示模式
enum EchoMode:
Normal //普通模式
NoEcho //不允许输入
Password //编辑及显示时为密码样式
PasswordEchoOnEdit //显示时为密码样式
setInputMask() // 设置输入掩码来限制输入字符
setValidator() // 为其设置验证器(validator)来验证输入
setCompleter() // 为其设置自动完成器

#include "widget.h"
#include <QLabel>
#include <QLineEdit>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QValidator>
#include <QRegExp>
#include <QCompleter>
// QLineEdit
// setMode() //设置文本编辑显示模式
// enum EchoMode:
// Normal //普通模式
// NoEcho //不允许输入
// Password //编辑及显示时为密码样式
// PasswordEchoOnEdit //显示时为密码样式
// setInputMask() // 设置输入掩码来限制输入字符
// setValidator() // 为其设置验证器(validator)来验证输入
// setCompleter() // 为其设置自动完成器
QHBoxLayout* getlayout(QWidget*,QWidget*);
Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    resize(300,300);
    QLabel *la1 = new QLabel("显示模式:");
    QLineEdit *ld1 = new QLineEdit;
    QLabel *la2 = new QLabel("输入掩码:");
    QLineEdit *ld2 = new QLineEdit;
    QLabel *la3 = new QLabel("输入验证:");
    QLineEdit *ld3 = new QLineEdit;
    QLabel *la4 = new QLabel("自动完成:");
    QLineEdit *ld4 = new QLineEdit;
    QHBoxLayout *ret1 = getlayout(la1,ld1);
    QHBoxLayout *ret2 = getlayout(la2,ld2);
    QHBoxLayout *ret3 = getlayout(la3,ld3);
    QHBoxLayout *ret4 = getlayout(la4,ld4);
    QVBoxLayout *mainlayout = new QVBoxLayout;
    mainlayout->addLayout(ret1);
    mainlayout->addLayout(ret2);
    mainlayout->addLayout(ret3);
    mainlayout->addLayout(ret4);
    setLayout(mainlayout);
    //显示模式
    ld1->setEchoMode(QLineEdit::PasswordEchoOnEdit);
    //输入掩码
    ld2->setInputMask("D99999999D");//输入前后不能为0的十位数
    //输入验证
    QRegExp rgx("\\d{11}");//输入十一位数 运用正则表达式
    QValidator *validator = new QRegExpValidator(rgx,this);
    ld3->setValidator(validator);
    //自动验证
    QStringList words;
    words << "math" << "macro" << "monther";
    QCompleter *completer = new QCompleter(words,this);
    completer->setCaseSensitivity(Qt::CaseInsensitive);//大小写不敏感
    ld4->setCompleter(completer);
}
QHBoxLayout* getlayout(QWidget* w1,QWidget *w2)
{
    QHBoxLayout *ret = new QHBoxLayout;
    ret->addStretch();
    ret->addWidget(w1);
    ret->addSpacing(10);
    ret->addWidget(w2);
    ret->addStretch();
    return ret;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值