对话框资源

news/2024/10/9 3:16:04 标签: qt, c++

优化登录框:

当用户点击取消按钮,弹出问题对话框,询问是否要确定退出登录,并提供两个按钮,yes|No,如果用户点击的Yes,则关闭对话框,如果用户点击的No,则继续登录

当用户点击的登录按钮,进行账号和密码的匹配,如果匹配成功,则弹出信息对话框,给出信息为,登录成功,并给出一个确定按钮,当用户点击该按钮后,关闭登录界面,弹出另一个界面

当账号和密码不匹配是,给出错误对话框,给出信息为账号和密码不匹配,是否重新登录,并提供两个按钮 Yes|No,如果用户点击了Yes,则清空密码框后,继续登录。如果用户点击的取消,则关闭登录界面

要求:静态成员函数版本和对象版本各至少实现一个

头文件:lili.h

#ifndef LILI_H
#define LILI_H

#include <QWidget>

namespace Ui {
class lili;
}

class lili : public QWidget
{
    Q_OBJECT

public:
    explicit lili(QWidget *parent = nullptr);
    ~lili();
public slots:
    void jump_slot()
    {
        this->show();
    }

private:
    Ui::lili *ui;
};

#endif // LILI_H

头文件:widget.h

#ifndef WIDGET_H
#define WIDGET_H
#include<QLineEdit>
#include <QWidget>
#include<QPushButton>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
signals:
    void jump();
private slots:
    void my_slot();
    void my_slot1();

private:
    Ui::Widget *ui;
    QLineEdit *edit1;
    QLineEdit *edit2;
    QPushButton *btn1;
    QPushButton *btn2;

};
#endif // WIDGET_H

源文件:lili.cpp

#include "lili.h"
#include "ui_lili.h"

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

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

源文件:main.cpp

#include "widget.h"
#include "lili.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    lili l;
    QObject::connect(&w,&Widget::jump,&l,&lili::jump_slot);
    return a.exec();
}

源文件:widget.cpp

#include "widget.h"
#include "ui_widget.h"
#include<QDebug>
#include<QIcon>
#include<QPushButton>
#include<QLineEdit>
#include<QLabel>
#include <QMessageBox>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowTitle("lili's window");
    this->setWindowIcon(QIcon(":/tp/f54cccba4ab9b9122909fb0e0a4f3d3.jpg"));
    this->setMaximumSize(800,600);
    this->setMinimumSize(400,300);
    this->setFixedSize(500,400);
    //this->resize(800,600);
    //this->set(QIcon("D:/BaiduNetdiskDownload/qt/yingyong/7adcf1a6baf7073e8434ae912bbb52a.png"));
    this->setWindowOpacity(0.9);
    this->move(400,300);
    //QPainter a(this);
    //a.drawPixmap(rect(),QPixmap("D:/BaiduNetdiskDownload/qt/yingyong/7adcf1a6baf7073e8434ae912bbb52a.png"),QRect());

    QLabel *lab3=new QLabel(this);
    lab3->resize(500,500);
    lab3->setStyleSheet("background:skyblue;");
    //QMovie *movie=new QMovie("");
    //lab3->setScaledContents(true);
    //lab3->setPixmap(QPixmap("D:/BaiduNetdiskDownload/qt/yingyong/218f6c69c7208efb13d66d558999dec.jpg"));
    lab3->setPixmap(QPixmap(":/tp/1111.png"));
    lab3->setScaledContents(true);




    btn1=new QPushButton(QIcon(":/tp/12067205a1d2c773274d113ab9594f8.jpg"),"登录",this);
    btn1->resize(60,30);
    btn1->move(150,300);
    btn1->setStyleSheet("color:white;background:pink;border-radius:10px;");

    btn2=new QPushButton("注册",this);
    btn2->resize(btn1->size());
    btn2->move(btn1->x()+btn1->width()+70,btn1->y());
    btn2->setStyleSheet("color:white;background:pink;border-radius:10px;");
    btn2->setIcon(QIcon(":/tp/1359e195af6400e83b7490ddae6808f.jpg"));


    QLabel *lab1=new QLabel("账号:",this);
    lab1->resize(50,30);
    lab1->move(btn1->x()-60,btn1->y()-90);
    lab1->setStyleSheet("color:black;");



    QLabel *lab2=new QLabel("密码:",this);
    lab2->resize(50,30);
    lab2->move(btn1->x()-60,lab1->y()+40);
    lab2->setStyleSheet("color:black;");


    edit1=new QLineEdit(this);
    edit1->resize(250,30);
    edit1->move(lab1->x()+lab1->width()+10,lab1->y());
    edit1->clear();
    edit1->setStyleSheet("color:pink");
    edit1->setAlignment(Qt::AlignCenter);
    edit1->setPlaceholderText("请输入账号");

    edit2=new QLineEdit("密码",this);
    edit2->resize(250,30);
    edit2->move(edit1->x(),edit1->y()+40);
    edit2->clear();
    edit2->setStyleSheet("color:pink");
    edit2->setAlignment(Qt::AlignCenter);
    edit2->setPlaceholderText("请输入密码");
    edit2->setEchoMode(QLineEdit::Password);

    //connect(btn2,SIGNAL(clicked()),this,SLOT(close()));
    connect(btn1,&QPushButton::clicked,this,&Widget::my_slot);
    connect(btn2,&QPushButton::clicked,this,&Widget::my_slot1);
}
void Widget::my_slot()
{
    QString username =edit1->text();
    QString password =edit2->text();
    if(username==password)
    {
        QMessageBox box(QMessageBox::Information,
                        "信息",
                        "登陆成功",
                        QMessageBox::Ok,
                        this);
        box.setButtonText(QMessageBox::Ok,"确定");
        box.setDefaultButton(QMessageBox::Ok);
        int btn=box.exec();
        if(btn==QMessageBox::Ok)
        {
            this->close();
            emit jump();
        }
    }else{
        int btn1=QMessageBox::warning(this,
                                      "错误",
                                      "账号和密码不相等,是否重新登陆",
                                      QMessageBox::Yes|QMessageBox::No,
                                      QMessageBox::Yes);
        if(btn1==QMessageBox::Yes)
        {
            edit2->clear();
        }else if(btn1==QMessageBox::No)
        {
            this->close();
        }
    }
}
void Widget::my_slot1()
{
    QMessageBox box(QMessageBox::Question,
                    "error",
                    "是否退出登录",
                    QMessageBox::Yes|QMessageBox::No,
                    this);
    box.setDefaultButton(QMessageBox::Yes);
    int btn=box.exec();
    if(btn==QMessageBox::Yes)
    {
        this->close();
    }
}

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


http://www.niftyadmin.cn/n/5695189.html

相关文章

Docker 安装 Citus 单节点集群:全面指南与详细操作

Docker 安装 Citus 单节点集群&#xff1a;全面指南与详细操作 文章目录 Docker 安装 Citus 单节点集群&#xff1a;全面指南与详细操作一 服务器资源二 部署图三 安装部署1 创建网络2 运行脚本1&#xff09;docker-compose.cituscd1.yml2&#xff09;docker-compose.cituswk1.…

报错笔记

报错笔记 若依报错若依跳转新页面&#xff0c;同时关闭当前页面 element UI组件使用报错使用element UI Table 高亮显示某一行 若依报错 若依跳转新页面&#xff0c;同时关闭当前页面 使用场景如&#xff1a;当在新增/编辑路由页面提交成功后&#xff0c;需要关闭当前页&#…

天玑 9400 基本确认:4大升级,一代“冰龙”来了

去年&#xff0c;天玑9300 破釜沉舟&#xff0c;打破了A系不可击败的神话。但今年&#xff0c;对安卓阵营来说&#xff0c;才是扬眉吐气的时刻。 因为芯片人才的流失&#xff0c;果子已经雄风不再。即使是 4nm 工艺打3nm工艺&#xff0c;天玑 9300 的 GPU效能&#xff0c;也压…

ES postman操作全量修改,局部修改,删除

全量修改 修改需要调用的url 地址是http://192.168.1.108:9200/shopping/_doc/1001&#xff0c;调用方法使用put 只修改指定的需求的内容的请求方式 post方式就是局部修改 http://192.168.1.108:9200/shopping/_update/1001&#xff0c;请求方式post 上图是只修改id 为1001数…

C语言进阶版第18课—动态内存管理

文章目录 1. 动态内存管理2. malloc和free函数2.1 malloc函数2.2 free函数 3. calloc和realloc函数3.1 calloc函数3.2 realloc函数 4. 常见的动态内存错误4.1 对NULL指针的解引用操作4.2 对动态开辟的空间越界访问4.3 对非动态开辟的内存使用free释放4.4 使用free释放一块动态开…

机器学习K近邻算法——分类问题K近邻算法示例

针对“数据8.1”&#xff0c;讲解分类问题的K近邻算法&#xff0c;以V1&#xff08;转型情况&#xff09;为响应变量&#xff0c;以V2&#xff08;存款规模&#xff09;、V3&#xff08;EVA&#xff09;、V4&#xff08;中间业务收入&#xff09;、V5&#xff08;员工人数&…

【C语言刷力扣】1436.旅行终点站

题目&#xff1a; 解题思路&#xff1a; 两层循环查找&#xff0c;第一次循环中初始化 destination 为 path中每次旅行的终点作为最终的终点。二次循环查找当前 destination &#xff0c;若是作为某次旅行的起点&#xff0c;说明不是最后的终点。 char* destCity(char ***paths…

使用boost库写共享内存代码,怎么判断共享内存是否已经存在

使用boost::interprocess::shared_memory_object仅创建共享内存时&#xff0c;如果共享内存已存在会抛boost::interprocess::interprocess_exception类型的异常&#xff0c;并且抛出的异常的error_code是boost::interprocess::error_code_t::already_exists_error&#xff0c;可…