上学期这个时候头一次接触Qt,就做了一个简单QQ登录界面。感觉Qt上手还是很容易的,但是这个代码功能不是很完美。因为是去年做的,现在懒得再完善功能了,但是对于初学者应付一下小小的作业还是ok的(哈哈哈哈哈小声bb)。
对界面有美观有要求的臭弟弟臭妹妹们,看过来就对了!
一、效果图
1.登录之后转换的页面就是张图片,以假乱真......
2.注册账号和找回密码的label上加了超链接,下面会附上代码。改变按键属性,没有鼠标经过的时候是透明的,有鼠标经过变粉色
二、工程文件
三、代码
1.test.pro
QT += core gui widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp\
mainwindow.cpp \
login.cpp \
qqinterface.cpp
HEADERS += mainwindow.h \
login.h \
qqinterface.h
FORMS += mainwindow.ui \
login.ui \
qqinterface.ui
RESOURCES += \
rc.qrc
2.login.h
#ifndef LOGIN_H
#define LOGIN_H
#include
namespace Ui {
class Login;
}
class Login : public QDialog
{
Q_OBJECT
public:
explicit Login(QWidget *parent = 0);
~Login();
private slots:
void on_pushButton_back_clicked();
private:
Ui::Login *ui;
};
#endif // LOGIN_H
3.mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
namespace Ui {
class MainWindow;
}
//登录状态
typedef enum
{
ONLINE = 1,
ACTIVE,
AWEY,
BUSY,
NOT_DISTURB,
HIDE,
OFFLINE
}LoginState;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots://登录的信号槽
void login();
void closeThis();
void on_label_url_linkHovered(const QString &link);
void on_label_url_linkActivated(const QString &link);
void on_pushButton_no_clicked();
void on_pushButton_QR_clicked();
void on_pushButton_ok_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
4.qqinterface.h
#ifndef QQINTERFACE_H
#define QQINTERFACE_H
#include
namespace Ui {
class QQInterface;
}
class QQInterface : public QDialog
{
Q_OBJECT
public:
explicit QQInterface(QWidget *parent = 0);
~QQInterface();
private:
Ui::QQInterface *ui;
};
#endif // QQINTERFACE_H
5.login.cpp
#include "login.h"
#include "ui_login.h"
#include "mainwindow.h"
Login::Login(QWidget *parent) :
QDialog(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
this->setWindowTitle("**小姐姐的QQ");
}
Login::~Login()
{
delete ui;
}
void Login::on_pushButton_back_clicked()
{
this->close();
MainWindow *mainwindow = new MainWindow();
mainwindow->show();
}
6.main.cpp
#include "mainwindow.h"
#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
7.mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
#include
#include
#include
#include "login.h"
#include "qqinterface.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
//connect(谁,发出了什么信号;谁,执行什么操作)
ui->setupUi(this);
connect(this->ui->pushButton_ok,SIGNAL(clicked(bool)),this,SLOT(login()));
//connect(this->ui->pushButton_no,SIGNAL(clicked(bool)),this,SLOT(closeThis()));
this->ui->label_url->setText("注册账号");//超链接
this->ui->label_url->setOpenExternalLinks(true);
this->ui->label_url_1->setText("找回密码");//超链接
this->ui->label_url_1->setOpenExternalLinks(true);
this->setWindowTitle("**小姐姐的QQ");
//QIcon a(QPixmap(":/image/img/15.gif"));//给QQ界面添加图片
//QIcon *img =new QImage();
//img->load(":/image/img/15.gif");
//this->ui->label_6->setPixmap(
//QPixmap::fromImage(*img));//设置背景图片
// ui->setupUi(this);
//ui->label_6->setScaledContents(true);
//QMovie *movie = new QMovie(":/image/img/15.gif");
//ui->label_6->setMovie(movie);
// movie->start();
//this->ui->pushButton_ok->set
this->ui->label->text();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::login()
{
static int count=0;
QString name = this->ui->lineEdit_acount->text();
QString passwd = this->ui->lineEdit_passwd->text();
if(name == "1575615708" && passwd == "123456789"){
qDebug()<< "登录成功";
}else{
qDebug()<< "登录失败";
count++;
if(count>=3){
disconnect(this->ui->pushButton_ok,SIGNAL(clicked(bool)),this,SLOT(login()));
}
}
}
void MainWindow::on_label_url_linkHovered(const QString &link)
{
qDebug()<<"Hover"<close();
}
void MainWindow::on_pushButton_QR_clicked()
{
this->close();
Login *login = new Login();
login->show();
}
void MainWindow::on_pushButton_ok_clicked()
{
QString name = this->ui->lineEdit_acount->text();
QString passwd = this->ui->lineEdit_passwd->text();
if(name == "1575615708" && passwd == "123456789")
{
this->close();
QQInterface *qqInterface = new QQInterface();
qqInterface->show();
}
else
{
MainWindow *mainwindow = new MainWindow();
mainwindow->show();
}
}
8.qqinterface.cpp
#include "qqinterface.h"
#include "ui_qqinterface.h"
QQInterface::QQInterface(QWidget *parent) :
QDialog(parent),
ui(new Ui::QQInterface)
{
ui->setupUi(this);
this->setWindowTitle("登录成功!");
}
QQInterface::~QQInterface()
{
delete ui;
}
四、赠几张个人感觉特别有feel的img哈哈哈哈哈哈哈
一个简单的小项目希望可以帮助到你们,哪怕是一点点♥