实现聊天软件登陆界面

.h文件 

#ifndef MY_WIN_H
#define MY_WIN_H

#include <QWidget>
#include <QDebug>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMessageBox>

QT_BEGIN_NAMESPACE
namespace Ui { class my_win; }
QT_END_NAMESPACE

class my_win : public QWidget
{
    Q_OBJECT

public slots:
    void judge();
    void quit();


public:
    my_win(QWidget *parent = nullptr);
    ~my_win();

private:
    Ui::my_win *ui;
    QLineEdit *edit_username;
    QLineEdit *edit_passwd;

};
#endif // MY_WIN_H

.cpp文件

#include "my_win.h"
#include "ui_my_win.h"

my_win::my_win(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::my_win)
    ,edit_username(new QLineEdit(this))
    ,edit_passwd(new QLineEdit(this))
{
    ui->setupUi(this);
    QVBoxLayout *vbox=new QVBoxLayout(this);
    QHBoxLayout *hbox=new QHBoxLayout(this);
    this->setWindowIcon(QIcon("C:\\Users\\15721\\Desktop\\LEARN\\icon\\user.png"));
    this->setWindowTitle("聊天登录");
    this->setStyleSheet(QString::fromUtf8("background-color: rgb(192,192,192);"));

    this->setFixedSize(550,350);

    QLabel *lab1=new QLabel(this);
    lab1->setPixmap(QPixmap("C:\\Users\\15721\\Desktop\\LEARN\\icon\\logo.png"));
    lab1->resize(550,150);
    lab1->move(0,0);
    lab1->setScaledContents(true);

    QLabel *lab_username=new QLabel(this);
    QLabel *lab_passwd=new QLabel(this);

    lab_username->setPixmap(QPixmap("C:\\Users\\15721\\Desktop\\LEARN\\icon\\userName.jpg"));
    lab_passwd->setPixmap(QPixmap("C:\\Users\\15721\\Desktop\\LEARN\\icon\\passwd.jpg"));
    lab_username->resize(40,40);
    lab_passwd->resize(40,40);
    lab_username->setScaledContents(true);
    lab_passwd->setScaledContents(true);
    lab_username->move(100,170);
    lab_passwd->move(100,220);

    edit_username->resize(200,40);
    edit_passwd->resize(200,40);

    edit_username->move(lab_username->width()+130,170);
    edit_passwd->move(lab_username->width()+130,220);

    edit_passwd->setEchoMode(QLineEdit::Password);

    QPushButton *btn_login=new QPushButton("登录",this);
    QPushButton *btn_exit=new QPushButton("退出",this);
    connect(btn_exit,&QPushButton::clicked,this,&my_win::quit);

    connect(btn_login,&QPushButton::clicked,this,&my_win::judge);

    btn_login->resize(50,40);
    btn_exit->resize(50,40);

    btn_login->move(300,275);
    btn_exit->move(400,275);


}

void my_win::judge(){
    QString username=edit_username->text();
    QString passwd=edit_passwd->text();
    if(username=="admin"&&passwd=="123456"){
        qDebug()<<"登陆成功";
        QMessageBox mbox(QMessageBox::NoIcon,"登陆成功","登陆成功",QMessageBox::Yes);
        int res=mbox.exec();
        if(QMessageBox::Yes==res){
            exit(0);
        }


    }else{
        qDebug()<<"登陆失败";
         QMessageBox mbox(QMessageBox::Question,"登陆失败","是否重新登录",QMessageBox::Yes|QMessageBox::No);
         int res=mbox.exec();
         if(res==QMessageBox::Yes){
                edit_username->clear();
                edit_passwd->clear();
         }else if(res==QMessageBox::No){
             exit(0);
         }
    }

}

void my_win::quit(){
    QMessageBox mbox(QMessageBox::Question,"退出","是否要退出",QMessageBox::Yes|QMessageBox::No);
    int res=mbox.exec();
    if(QMessageBox::Yes==res){
        exit(0);
    }else if(QMessageBox::No==res){
        edit_username->clear();
        edit_passwd->clear();
    }
}

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

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值