QT day2模仿QQ登录界面

头文件
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QDebug>           //包含信息调试类头文件
#include <QIcon>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT
public:
    void do_login();
public:
    Widget(QWidget *parent = nullptr);
    ~Widget();


private:
    Ui::Widget *ui;
    QLineEdit *edt1;                 //用户所对应的编辑器
    QLineEdit *edt2;                 //密码所对应的编辑器
};
#endif

widget.cpp文件

#include "widget.h"
#include "ui_widget.h"

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

    //------------设定窗体改变名称并设置窗口图标、尺寸固定----------

    this->setFixedSize(538,414);                    //设置窗口的尺寸
    this->setWindowTitle("QQ");                     //设置窗口标题
    this->setWindowIcon(QIcon(":/icon/qq.png"));    //设置窗口图标
    this->setStyleSheet("background-color:white");  //设置背景色


    //---------中间放log图---------------------

    QLabel *lab1 = new QLabel;                      //定义一个标签
    lab1->setParent(this);
    lab1->resize(543,160);
    lab1->setPixmap(QPixmap(":/icon/TS(VXL98MM`XV}L[K({T8XB.png"));
    lab1->setScaledContents(true);                  //设置组件内容自适应


    //---------------账户密码及其logo-------------
    int n=-20;
    QLabel *lab2 = new QLabel("账户",this);
    lab2->move(188+n,200);
    qDebug() << lab2->size();
    lab2->resize(100,40);
    QLabel *lab2_1 = new QLabel;
    lab2_1->setParent(this);
    lab2_1->setPixmap(QPixmap(":/icon/pass.png"));
    lab2_1->move(160+n,210);
    lab2_1->resize(20,20);
    lab2_1->setScaledContents(true);                    //设置组件内容自适应

    QLabel *lab3 = new QLabel("密码",this);
    lab3->move(188+n,230);
    qDebug() << lab3->size();
    lab3->resize(100,40);
    QLabel *lab3_1 = new QLabel;
    lab3_1->setParent(this);
    lab3_1->setPixmap(QPixmap(":/icon/pass.png"));
    lab3_1->move(160+n,240);
    lab3_1->resize(20,20);
    lab3_1->setScaledContents(true);                    //设置组件内容自适应


    //----------------账户密码的编辑框------------

    edt1 = new QLineEdit;                   //定义一个行编辑器,实例化对象时使用无参构造,账户所对应的编辑器
    edt1->setParent(this);
    edt1->move(230+n,200);
    edt1->resize(200,30);
    edt1->setPlaceholderText("账号/邮箱/手机号");



    edt2 = new QLineEdit;                   //定义一个行编辑器,实例化对象时使用无参构造,密码所对应的编辑器
    edt2->setParent(this);
    edt2->move(230+n,240);
    edt2->resize(200,30);
    edt2->setPlaceholderText("/密码");
    edt2->setEchoMode(QLineEdit::Password);//设置回显模式为密码

    //----------登录取消按钮---------------------------

    int m=20;
    QPushButton *btn1 = new QPushButton("登录",this);         //定义一个按钮,实例化对象时同时指定父组件及其文本内容
    btn1->move(180+m,300);
    btn1->setStyleSheet("background-color:rgb(#06BBFC)");    //设置按钮颜色

    QPushButton *btn2 = new QPushButton("取消",this);         //定义一个按钮,实例化对象时同时指定父组件及其文本内容
    btn2->move(300+m,300);
    btn2->setStyleSheet("background-color:rgb(#06BBFC)");    //设置按钮颜色



   connect(btn1,&QPushButton::clicked,this,&Widget::do_login); //将登录按钮与do_login()函数“连接”
   //connect(btn2,&QPushButton::clicked,this,this->close());
   connect(btn2,&QPushButton::clicked,this,[&](){
       this->close();
   });
}

Widget::~Widget()
{
    delete ui;
}
void Widget::do_login()
{
    if(edt1->text() == "admine" && edt2->text() == "123456")
    {
        qDebug() << "登录成功";
    }
    else
    {
        qDebug() << "账户密码不匹配";
    }
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值