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界面图
效果图: