qt做一个登录界面

要求:
1、给窗体改变名称并设置窗口图标、尺寸固定
2、中间放log图
3、用户名和密码使用图片完成
4、账户用明文模式,密码用密文模式
5、点击登录后,将界面上的用户名和“admin”比较,密码和“123456”比较,如果匹配成功,则输出登录成功,如果匹配失败,则输出“账户密码不匹配”,并清空密码框(clear)
6、点击取消后,关闭整个界面

#include "widget.h"
#include "ui_widget.h"
QLineEdit *edt1;
QLineEdit *edt2;
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置窗口标题
     this->setWindowTitle("my_homework");
    //设置窗口图标
    this->setWindowIcon(QIcon("D:\\zhuomian\\qq.png"));

    //固定窗口尺寸
    this->setFixedSize(530,330);

    //设置logo
    QLabel *lab=new QLabel(this);
    lab->resize(530,330);
    lab->setPixmap(QPixmap("D:\\zhuomian\\logo.png"));
    lab->setScaledContents(true);

    //设置登录账号
    QLabel *lab1=new QLabel(this);
    lab1->move(350,255);
    lab1->setPixmap(QPixmap("D:\\zhuomian\\userName.jpg"));
    lab1->setScaledContents(true);

    QLineEdit *edt1= new QLineEdit(this);
    edt1->move(390,250);
    edt1->resize(135,25);

    //设置登录密码
    QLabel *lab2=new QLabel(this);
    lab2->move(350,285);
    lab2->setPixmap(QPixmap("D:\\zhuomian\\passwd.jpg"));
    lab2->setScaledContents(true);

    QLineEdit *edt2= new QLineEdit(this);
    edt2->move(390,280);
    edt2->resize(135,25);
    edt2->setEchoMode(QLineEdit::Password); //设置回显模式

    //登录按钮
    QPushButton *btn1=new QPushButton("登录",this);
    btn1->move(415,305);
    btn1->resize(40,25);
    //取消按钮
    QPushButton *btn2=new QPushButton("取消",this);
    btn2->move(465,305);
    btn2->resize(40,25);
    //将按钮btn1发射的信号,手动连接到界面本身的自定义槽函数中
    connect(btn1,&QPushButton::clicked,this,&Widget::on_clicked_btn1);

    //将btn2发射的信号,手动连接到界面本身的自定义槽函数中
    connect(btn2,&QPushButton::clicked,this,&Widget::on_clicked_btn2);
}

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

void Widget::on_clicked_btn1()
{
    if(edt1->text()=="admin"&&edt2->text()=="123456")
            {
                qDebug()<<"登录成功";
            }
            else
            {
                qDebug()<<"账号密码不匹配";
                edt2->clear();
            }
}
void Widget::on_clicked_btn2()
{
    this->close();
}

猜你喜欢

转载自blog.csdn.net/k_weihgl/article/details/129978046
今日推荐