2024-3-22-Qtday3作业

1> 思维导图

2>

要求:

使用手动连接,将登录框中的取消按钮使用qt4版本的连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数

将登录按钮使用qt5版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为"admin",密码是否为"123456",如果账号密码匹配成功,则输出"登录成功",并关闭该界面,如果匹配失败,则输出登录失败,并将密码框中的内容清空

源代码:

//widge.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);
    connect(ui->closeBtn, SIGNAL(clicked()),
            this, SLOT(close_slot()));

    connect(ui->logInBtn, &QPushButton::clicked,
            this, &Widget::log_in_slot);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::close_slot()
{
    this->close();
}

void Widget::log_in_slot()
{
    if( ui->usrEdit->text() == "admin" && ui->pwdEdit->text() == "123456")
    {
        qDebug() << " 登录成功 ";
        this->close();
    }
    else
    {
        qDebug() << " 登录失败 ";
        ui->pwdEdit->setText("");
    }

}

效果图:

3> 自己完成一个使用qss的登陆窗口界面

源代码:

//widget.cpp

#include "widget.h"
#include "ui_widget.h"
/*3> 自己完成一个使用qss的登陆窗口界面。*/

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->frame->resize(1080,608);
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    QMovie *mv1 = new QMovie(":/GIF/left.gif");
    ui->leftLabel->setScaledContents(true);
    ui->leftLabel->setMovie(mv1);
    mv1->start();
    QMovie *mv2 = new QMovie(":/GIF/right.gif");
    ui->rightLabel->setScaledContents(true);
    ui->rightLabel->setMovie(mv2);
    mv2->start();



}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_closeBtn_clicked()
{
    this->close();
}


//qss代码
*{
	
	background-color: rgb(255, 255, 255);
}
QFrame#frame{
	background-color: rgb(10, 10, 10);
}

QLineEdit#idEdit{
	
	background-color: rgb(230, 230, 230);
}
#pwdEdit{
background-color: rgb(230, 230, 230);
}
QLineEdit:hover#idEdit{
	
	background-color: rgb(230, 255, 255);
}
#pwdEdit{
background-color: rgb(230, 255, 255);
}
QPushButton#logInBtn{
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(255, 92, 33, 255), stop:1 rgba(255, 153, 55, 255));
	border:none;
	font: 25 16pt "等线 Light";
	font: 16pt "黑体";
}

QPushButton:pressed#logInBtn{
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(255, 92, 33, 255), stop:1 rgba(255, 153, 55, 255));
	border:none;
	font: 25 16pt "等线 Light";
	font: 16pt "黑体";
	padding-top:10px;
	padding-left:10px;
}
QPushButton:hover#logInBtn{
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(255, 92, 33, 255), stop:1 rgba(255, 255, 100, 255));
	border:none;
	font: 25 16pt "等线 Light";
	font: 16pt "黑体";
}
#closeBtn{
	
	
	background-color: rgb(127, 127, 191);
	font: 26pt "黑体";
}
QLabel#idLabel{
	
	border-image: url(:/GIF/idlogo.png);
	background-color: rgb(230, 230, 230);
}
#pwdLabel{
	border-image: url(:/GIF/pwlogo.png);
	background-color: rgb(230, 230, 230);
}
#logoLabel{
	border-image:url(:/GIF/qqlogo.png);
}
#label{
	
	background-color: rgba(255, 255, 255, 0);
	border-image: url(:/GIF/logo.png);
}

效果:

相关推荐
Logintern091 分钟前
使用VS Code进行Python编程的一些快捷方式
开发语言·python
Multiple-ji12 分钟前
想学python进来看看把
开发语言·python
一个小白133 分钟前
C++——list模拟实现
开发语言·c++
bug总结34 分钟前
新学一个JavaScript 的 classList API
开发语言·javascript·ecmascript
Nicole Potter41 分钟前
请说明C#中的List是如何扩容的?
开发语言·面试·c#
程序员老舅1 小时前
C++ Qt项目教程:WebServer网络测试工具
c++·qt·测试工具·webserver·qt项目·qt项目实战
靡不有初1111 小时前
CCF-CSP第18次认证第一题——报数【两个与string相关的函数的使用】
c++·学习·ccfcsp
十八朵郁金香1 小时前
通俗易懂的DOM1级标准介绍
开发语言·前端·javascript
阿尔法波1 小时前
python与pycharm如何设置文件夹为源代码根目录
开发语言·python·pycharm
xing25162 小时前
pytest下allure
开发语言·python·pytest