
加上这个passwordline->setEchoMode(QLineEdit::Password);
- #include "widget.h"
-
-
- Widget::Widget(QWidget *parent)
- : QWidget(parent)
- {
-
- this->resize(300,200);
- this->setWindowTitle("登录窗口");
-
- usrname=new QLabel("用户名",this);
- password=new QLabel("密码",this);
-
- usrnameline=new QLineEdit(this);
- passwordline=new QLineEdit(this);
- passwordline->setEchoMode(QLineEdit::Password);
-
- regist_btn=new QPushButton("注册",this);
- login_btn=new QPushButton("登录",this);
-
- QGridLayout* up_late=new QGridLayout;
- up_late->addWidget(usrname,0,0);
- up_late->addWidget(usrnameline,0,1);
- up_late->addWidget(password,1,0);
- up_late->addWidget(passwordline,1,1);
-
-
- QHBoxLayout* shui_ping=new QHBoxLayout;
- shui_ping->addWidget(regist_btn);
- shui_ping->addWidget(login_btn);
-
- QVBoxLayout* together=new QVBoxLayout(this);
- together->addLayout(up_late);
- together->addLayout(shui_ping);
-
- connect(passwordline,&QLineEdit::textChanged,[](const QString& text){
- QRegExp exp("^[A-Z]+[a-z0-9_]{7,}");
-
- if(exp.exactMatch(text)){
- qDebug()<<"输入格式正确";
- }else{
- qDebug()<<"输入格式错误";
- }
- });
-
- connect(login_btn,&QPushButton::clicked,[=](){
- if(usrnameline->text()=="peter"&&passwordline->text()=="A1234567"){
- QMessageBox::information(this,"提示","输入正确");
-
- }else{
- QMessageBox::information(this,"提示","输入错误");
- }
- });
- }
-
- Widget::~Widget()
- {
- }
-
-