QT編寫簡單登錄界面的實現(xiàn)示例
更新時間:2024年02月11日 09:44:40 作者:????????傻豬豬一枚
登陸界面是網(wǎng)頁中常見的界面,本文主要介紹了QT編寫簡單登錄界面的實現(xiàn)示例,具有一定的參考價值,感興趣的可以了解一下
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界面圖

效果圖:



到此這篇關(guān)于QT編寫簡單登錄界面的實現(xiàn)示例的文章就介紹到這了,更多相關(guān)QT 登錄界面內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C語言函數(shù)聲明以及函數(shù)原型超詳細(xì)講解示例
這篇文章主要介紹了C語言函數(shù)聲明以及函數(shù)原型超詳細(xì)講解,C語言代碼由上到下依次執(zhí)行,原則上函數(shù)定義要出現(xiàn)在函數(shù)調(diào)用之前,否則就會報錯。但在實際開發(fā)中,經(jīng)常會在函數(shù)定義之前使用它們,這個時候就需要提前聲明2023-02-02
C++/JAVA/C#子類調(diào)用父類函數(shù)情況總結(jié)
今天小編就為大家分享一篇關(guān)于C++/JAVA/C#子類調(diào)用父類函數(shù)情況總結(jié),小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03

