qt 登录页面点击事件

实现

复制代码
#include "loginwidget.h"
#include "ui_loginwidget.h"
#define Account "admin"
#define Pwd "123456"
#include <QDebug>

LoginWidget::LoginWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LoginWidget)
{
    ui->setupUi(this);
    this->setWindowTitle("有道笔记");
    this->setWindowIcon(QIcon(":/pictrue/logo_icon.png"));
    //    this->setStyleSheet("background-color:white;border-radius:10px");
    this->setStyleSheet("background-color:white;border-radius:10px");
    this->resize(788,1243);
    this->setFixedSize(788,1243);
    this->setWindowFlag(Qt::FramelessWindowHint);//隐藏表头

    QLabel * lab1 = new QLabel(this);
    lab1->resize(150,150);
    lab1->move(638,5);
    //    lab1->setStyleSheet("background-color:red");
    lab1->setPixmap(QPixmap(":pictrue\\right_top.png"));
    lab1->setScaledContents(true);//图片自适应

    topBtn = new QPushButton(this);
    topBtn->resize(lab1->width(),lab1->height());
    topBtn->move(lab1->x(),lab1->y());
    topBtn->setStyleSheet("background:transparent");
    connect(topBtn,&QPushButton::clicked,this,&LoginWidget::change);


    QLabel * lab2 = new QLabel(this);
    lab2->resize(230,230);
    lab2->move(269,85);
    //    lab2->setStyleSheet("background-color:red");
    lab2->setPixmap(QPixmap(":/pictrue/logo.png"));
    lab2->setScaledContents(true);//图片自适应

    edit1 = new QLineEdit(this);
    edit1->setPlaceholderText("  请输入邮箱账号");
    edit1->setStyleSheet("barder-radius:10px;border: 1px solid gray;");
    edit1->resize(630,70);
    edit1->move(75,365);
    edit1->setMaxLength(18);

    edit2 = new QLineEdit(this);
    edit2->setPlaceholderText("  请输入邮箱密码");
    edit2->setStyleSheet("barder-radius:10px;border: 1px solid gray;");
    edit2->resize(630,70);
    edit2->move(75,465);
    edit2->setMaxLength(18);
    edit2->setEchoMode(QLineEdit::Password);

    QPushButton * btn1 = new QPushButton(this);
    btn1->setText("登录");
    btn1->setStyleSheet("background-color:rgb(101,136,246);border-radius:10px;color:white");
    btn1->resize(630,70);
    btn1->move(75,665);
    connect(btn1,&QPushButton::clicked,this,&LoginWidget::login);


    btn2 = new QPushButton(this);
    btn2->setText("手机号登录");
    btn2->setStyleSheet("background-color:rgb(241,243,245);border-radius:10px;");
    btn2->resize(630,70);
    btn2->move(75,775);


    QLabel * lab3 = new QLabel(this);
    lab3->resize(666,294);
    lab3->move(70,926);
    //    lab2->setStyleSheet("background-color:red");
    lab3->setPixmap(QPixmap(":/pictrue/bottom.png"));
    lab3->setScaledContents(true);//图片自适应



    lab4 = new QLabel(this);
    lab4->resize(722,1125);
    lab4->move(28,105);
    //    lab1->setStyleSheet("background-color:red");
    lab4->setPixmap(QPixmap(":pictrue\\ewm.png"));
    lab4->setScaledContents(true);//图片自适应
    lab4->setHidden(true);

}

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

void LoginWidget::close_fun()
{
        this->close();

}

void LoginWidget::login()
{

    if(this->edit1->text() == Account && this->edit2->text() == Pwd  ){
        qDebug()<<"login success";
        this->close();
    }else {
        if(this->edit1->text().size()!=0){
            this->edit1->clear();
        }

        this->edit2->clear();
        qDebug()<<"login faild";
    }

}

void LoginWidget::change()
{
   static int type = 0;
   if(type == 0){
     this->lab4->setHidden(false);
     type = 1;
     return;
   }
   if(type == 1){
     this->lab4->setHidden(true);
       type = 0;
       return;
   }


}

声明

复制代码
#ifndef LOGINWIDGET_H
#define LOGINWIDGET_H

#include <QWidget>
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>

namespace Ui {
class LoginWidget;
}

class LoginWidget : public QWidget
{
    Q_OBJECT

public:
    explicit LoginWidget(QWidget *parent = nullptr);
    ~LoginWidget();

    //槽函数
public slots:
    void close_fun();
    void login();
    void change();
signals:
    void my_signal();
private:
    Ui::LoginWidget *ui;
    QLabel * lab1;
    QPushButton *topBtn;
    QPushButton * btn2;
    QLineEdit * edit1 ;
    QLineEdit * edit2;
    QLabel * lab4 ;

};

#endif // LOGINWIDGET_H

相关推荐
灯澜忆梦8 小时前
GO_并发编程---定时器
开发语言·后端·golang
-银雾鸢尾-9 小时前
C#中的StringBuilder相关方法
开发语言·c#
-银雾鸢尾-9 小时前
C#中结构体与类的区别;抽象类与接口的区别
开发语言·c#
大模型码小白10 小时前
【Python零基础教程】继承、多态与魔法函数:面向对象编程三大核心特性详解
java·大数据·开发语言·人工智能·python·ai编程
段一凡-华北理工大学12 小时前
向量数据库实战:选型、调优与落地~系列文章12:文本分块策略实战:chunk_size 怎么选?重叠多少?
开发语言·数据库·后端·oracle·rust·工业智能体·高炉智能化
Ljwuhe12 小时前
C++——多态
开发语言·c++
心平气和量大福大13 小时前
C#-WPF-Window主窗体
开发语言·c#·wpf
从零开始的代码生活_14 小时前
C++ 继承详解:访问控制、对象模型、菱形继承与设计取舍
开发语言·c++·后端·学习·算法
云小逸14 小时前
【C++ 第七阶段:模板、泛型编程与工程综合详解】
开发语言·c++
Quz14 小时前
QML 信号与槽:直接绑定与跨文件通信
qt·编程语言·设计