QT編寫簡單登錄界面的實現(xiàn)示例
更新時間:2024年02月11日 09:44:40 作者:????????傻豬豬一枚
登陸界面是網頁中常見的界面,本文主要介紹了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界面圖

效果圖:



到此這篇關于QT編寫簡單登錄界面的實現(xiàn)示例的文章就介紹到這了,更多相關QT 登錄界面內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
C++最短路徑Dijkstra算法的分析與具體實現(xiàn)詳解
經典的求解最短路徑算法有這么幾種:廣度優(yōu)先算法、Dijkstra算法、Floyd算法。本文是對?Dijkstra算法的總結,該算法適用于帶權有向圖,可求出起始頂點到其他任意頂點的最小代價以及對應路徑,希望對大家有所幫助2023-03-03
C語言數(shù)據(jù)結構之雙向循環(huán)鏈表的實例
這篇文章主要介紹了C語言數(shù)據(jù)結構之雙向循環(huán)鏈表的實例的相關資料,需要的朋友可以參考下2017-06-06

