使用QT编写一个简单登录界面

main.cpp

cpp 复制代码
#include "widget.h"
#include "login.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;


    Login l;
    QObject::connect(&w,&Widget::log_btn,&l,&Login::lobin);
    w.show();

    return a.exec();
}

widget.cpp

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setWindowIcon(QIcon("C:\\Users\\13103321519\\Desktop\\pictrue\\pictrue\\qq.png"));
    this->setWindowTitle("QQ");
    //connect(ui->logButton,&QPushButton::clicked,this,&Widget::log_btn);

}

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

void Widget::on_logButton_clicked()
{
    if(ui->nameEdit->text() == "admin" && ui->passEdit->text() == "123456")
    {
        QMessageBox msg(QMessageBox::Information,"登陆成功","登陆成功",QMessageBox::Yes,this);
        int ret = msg.exec();
        if(ret == QMessageBox::Yes)
        {
            emit this->log_btn();
            this->close();
        }
    }
    else {
            emit this->Log_yes();
    }
}

void Widget::Log_yes()
{
    QMessageBox msge(QMessageBox::Critical,
                    "错误","账号密码不匹配,是否重新登陆",
                    QMessageBox::Yes | QMessageBox::No,
                    this);
    int ret = msge.exec();
    if(ret == QMessageBox::Yes)
    {
        ui->passEdit->clear();
    }
    else {
        this->close();
    }
}

void Widget::on_canButton_clicked()
{
    int ret = QMessageBox::question(this,
                                    "是否退出",
                                    "您是否确定要退出登陆?",
                                    QMessageBox::Yes | QMessageBox::No);
    if(ret == QMessageBox::Yes)
    {
        this->close();
    }
}
void Widget::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        point = event->pos();
    }
}
void Widget::mouseMoveEvent(QMouseEvent *event)
{
    this->move(event->globalPos()-point);
}

login.cpp

cpp 复制代码
#include "login.h"
#include "ui_login.h"

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

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

void Login::lobin()
{
    this->show();
}

ui界面图

效果图:

相关推荐
神仙别闹3 分钟前
基于C++ MFC实现动态分区分配存储管理
开发语言·c++·mfc
skr爱码士6 分钟前
03_第一个Qt项目:Hello World 的完整拆解
c++·qt·客户端
欧特克_Glodon17 分钟前
OpenCV计算机视觉开发入门与实践<十二>:XML 和 YAML 文件读写
xml·c++·opencv·计算机视觉
ryanuo725 分钟前
Shadcn/ui × Qt 6/QML:一次从 Web UI 到桌面 UI 的组件化实践
c++·qt·ui·shadcn
余额瞒着我当琳27 分钟前
C++--vector第二讲:手写 C++ STL:vector 源码剖析与迭代器失效分析
android·java·c++
郝学胜-神的一滴39 分钟前
[简化版 GAMES 104] 现代游戏引擎 06:从Tick时序到邮局模型,拆解确定性世界的底层密码
开发语言·c++·游戏引擎·图形渲染·软件开发·opengl
不会代码的小猴39 分钟前
6. Qt网络编程
开发语言·c++·笔记·qt·算法
沐风老师43 分钟前
从零开始学3dMax插件开发!
c++·3dmax插件·3dmax·maxscript
wuyk55511 小时前
98.C语言易混难点:字符数组与字符串指针的底层差异
c语言·开发语言·c++·stm32·嵌入式硬件·算法
峥无12 小时前
从0到1手撕红黑树:封装实现 my_map 与 my_set(SGI-STL 源码级深度解析)
开发语言·c++·笔记·算法·stl