C 语言

关注公众号 jb51net

关闭
首页 > 软件编程 > C 语言 > QT 登录界面

QT编写简单登录界面的实现示例

作者:​​​​​​​ 傻猪猪一枚

登陆界面是网页中常见的界面,本文主要介绍了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界面图

效果图:

到此这篇关于QT编写简单登录界面的实现示例的文章就介绍到这了,更多相关QT 登录界面内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文