Qt creator day3练习

2、升级优化自己应用程序的登录界面。

要求: 1. qss实现

2. 需要有图层的叠加 (QFrame)

3. 设置纯净窗口后,有关闭等窗口功能。

4. 如果账号密码正确,则实现登录界面关闭,另一个应用界面显示。

widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QMessageBox>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
signals:
    void my_signal();  //信号函数的声明
    void my_jump();  //第一个界面的跳转信号

private slots:
    void on_pushButton_2_clicked();

    void on_pushButton_3_clicked();

    void on_pushButton_clicked();

private:
    Ui::Widget *ui;
};
#endif // WIDGET_H

second.h

#ifndef SECOND_H
#define SECOND_H

#include <QWidget>

namespace Ui {
class Second;
}

class Second : public QWidget
{
    Q_OBJECT

public:
    explicit Second(QWidget *parent = nullptr);
    ~Second();

public slots:
    void jump_slot(); //第二个界面准备的槽函数

private:
    Ui::Second *ui;
};

#endif // SECOND_H

widget.cpp

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //将自定义的信号和Lambda表达式连接
    connect(this,&Widget::my_signal,[=](){

        //ui->resize(ui->width()+10,ui->height()+10);
    });
    //去掉头部
    this->setWindowFlag(Qt::FramelessWindowHint);

    //去掉空白部分
    this->setAttribute(Qt::WA_TranslucentBackground);
    connect(ui->lineEdit_2,SIGNAL(returnPressed()),ui->pushButton  //回车键登录
            ,SIGNAL(clicked()),Qt::UniqueConnection);

}

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


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

void Widget::on_pushButton_3_clicked()
{

}

void Widget::on_pushButton_clicked()
{
    QMessageBox *box = new QMessageBox();  //实例化一个box,用来弹出消息
    box->setWindowTitle("提示");

    if(QString(ui->lineEdit->text()) == "admin" && QString(ui->lineEdit_2->text()) == "123456")
    {
        box->setText("登录成功^_^");
        box->show();
        box->exec();
        this->close();
        emit my_jump(); // 触发信号
    }
    else
    {
        box->setText("账号密码错误");
        box->show();  //提示
        box->exec();  //等待用户响应
        ui->lineEdit->setText("");
        ui->lineEdit_2->setText("");
    }
}

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

相关推荐

  1. 数据结构练习3

    2024-06-18 02:56:05       48 阅读
  2. python练习3

    2024-06-18 02:56:05       35 阅读
  3. 3D立体盒子练习

    2024-06-18 02:56:05       53 阅读
  4. 力扣练习 3.27

    2024-06-18 02:56:05       40 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-18 02:56:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-18 02:56:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-18 02:56:05       82 阅读
  4. Python语言-面向对象

    2024-06-18 02:56:05       91 阅读

热门阅读

  1. kali - 配置静态网络地址 + ssh 远程连接

    2024-06-18 02:56:05       29 阅读
  2. 【Prometheus】自动化效率脚本

    2024-06-18 02:56:05       22 阅读
  3. CentOS:Kibana下载X-Pack

    2024-06-18 02:56:05       31 阅读
  4. 新手学习yolov8目标检测小记1

    2024-06-18 02:56:05       23 阅读
  5. 第十五届蓝桥杯Python大学B组国赛I题题解

    2024-06-18 02:56:05       28 阅读
  6. Spring Cloud 常用组件(上)

    2024-06-18 02:56:05       21 阅读