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

main.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

#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

#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界面图

 

效果图:

相关推荐

  1. python 编写登录界面

    2024-02-09 12:50:02       7 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-09 12:50:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-09 12:50:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-09 12:50:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-09 12:50:02       18 阅读

热门阅读

  1. Ubuntu 1804 And Above Coredump Settings

    2024-02-09 12:50:02       30 阅读
  2. 【Redis笔记】分布式锁及4种常见实现方法

    2024-02-09 12:50:02       30 阅读
  3. Rust入门2——随机数

    2024-02-09 12:50:02       31 阅读
  4. json模块(高维数据的存储与读取)

    2024-02-09 12:50:02       23 阅读
  5. Rust中的 Cell 和 RefCell

    2024-02-09 12:50:02       27 阅读
  6. 509. 斐波那契数

    2024-02-09 12:50:02       32 阅读
  7. 【Golang】定时任务Cron指南-毫秒级任务支持

    2024-02-09 12:50:02       31 阅读
  8. Flutter typedef 函数类型

    2024-02-09 12:50:02       30 阅读
  9. 速盾:dns解析和cdn加速的区别与联系

    2024-02-09 12:50:02       34 阅读
  10. C++ [NOIP2007 提高组] 矩阵取数游戏

    2024-02-09 12:50:02       28 阅读