升级优化自己应用程序的登录界面。
要求:1.qss实现
2.需要有图层的善加(QFrame)
3.设置纯净窗口后,有关闭等窗口功能。
4.如果账号密码正确,则实现登录界面关闭,另一个应用界面显示。
widget.cpp:
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//设置一个对象接受动图
QMovie *mv=new QMovie(":/home/wf.gif");
//将动图放入wflab中
this->ui->wflab->setMovie(mv);
//让动图动起来
mv->start();
//让图片自适应
this->ui->wflab->setScaledContents(true);
//去掉头部
this->setWindowFlag(Qt::FramelessWindowHint);
//去掉空白部分
this->setAttribute(Qt::WA_TranslucentBackground);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_Btn2_clicked()
{
//关闭界面
this->close();
}
void Widget::on_Btn_clicked()
{
//验证账号密码
if(this->ui->UsrEdit->text()=="Admin"&&this->ui->PassEdit->text()=="123456")
{
//关闭界面
this->close();
//触发信号
emit my_jump();
}
}
Second.cpp:
#include "second.h"
#include "ui_second.h"
Second::Second(QWidget *parent) :
QWidget(parent),
ui(new Ui::Second)
{
ui->setupUi(this);
}
Second::~Second()
{
delete ui;
}
void Second::jump_slot()
{
//显示
this->show();
}
main.cpp:
#include "widget.h"
#include"second.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
Second s;
QObject::connect(&w,&Widget::my_jump,&s,&Second::jump_slot);
return a.exec();
}
样式表代码
*{
background-color: rgb(255, 255, 255);
}
QFrame#frame{
}
QLabel#label{
background:transparent; /*完全透明*/
border-image: url(:/home/wg.png);
}
QLabel#label2{
background:transparent; /*完全透明*/
border-image: url(:/home/game.png);
}
QLabel#label3{
background:transparent; /*完全透明*/
border-image: url(:/home/1.png);
}
QLabel#label4{
background:transparent; /*完全透明*/
border-image: url(:/home/wei.png);
}
QLineEdit{
background:transparent; /*完全透明*/
border:none;
border-bottom:1px solid rgba(255, 255, 255, 144);
color: rgba(255, 255, 255, 120);
font: 14pt "华文隶书";
}
QPushButton#Btn{
font: 14pt "华文隶书";
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(252, 53, 34, 255), stop:1 rgba(255, 255, 0, 255));
border-radius:6px;
}
QPushButton#Btn:hover{ /*鼠标移动*/
font: 14pt "华文隶书";
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(255, 176, 0, 255), stop:1 rgba(255, 255, 70, 255));
border-radius:6px;
}
QPushButton#Btn:pressed{ /*鼠标按下*/
font: 14pt "华文隶书";
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(252, 53, 34, 255), stop:1 rgba(255, 255, 0, 255));
border-radius:6px;
padding-top:5px;
padding-left:5px;
}
QPushButton#Btn2{
background-color: rgba(255, 255, 255, 0);
}
QPushButton#Btn2:hover{ /*鼠标移动*/
background-color: rgb(255, 0, 0);
}