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);
}

效果:

相关推荐
上去我就QWER1 小时前
Qt中如何获取系统版本信息
开发语言·qt
我是苏苏2 小时前
C#高级:程序查询写法性能优化提升策略(附带Gzip算法示例)
开发语言·算法·c#
木木子99992 小时前
业务架构、应用架构、数据架构、技术架构
java·开发语言·架构
学涯乐码堂主7 小时前
GESP C++ 四级第一章:再谈函数(上)
c++·青少年编程·gesp·四级·学漄乐码青少年编程培训
微露清风7 小时前
系统性学习C++-第九讲-list类
c++·学习·list
大佬,救命!!!7 小时前
C++多线程同步与互斥
开发语言·c++·学习笔记·多线程·互斥锁·同步与互斥·死锁和避免策略
赵文宇(温玉)8 小时前
构建内网离线的“github.com“,完美解决内网Go开发依赖
开发语言·golang·github
qq7422349848 小时前
Python操作数据库之pyodbc
开发语言·数据库·python
Joker100858 小时前
仓颉自定义序列化:从原理到高性能多协议实现
开发语言
Adellle8 小时前
2.单例模式
java·开发语言·单例模式