0
点赞
收藏
分享

微信扫一扫

索引的数据结构

承蒙不弃 03-26 15:30 阅读 1
windows

完善对话框,点击登录对话框,如果账号和密码匹配,则弹出信息对话框,给出提示”登录成功“,提供一个Ok按钮,用户点击Ok后,关闭登录界面,跳转到其他界面

如果账号和密码不匹配,弹出错误对话框,给出信息”账号和密码不匹配,是否重新登录“,并提供两个按钮Yes|No,用户点击Yes后,清除密码框中的内容,继续让用户进行登录,如果用户点击No按钮,则直接关闭登录界面

如果用户点击取消按钮,则弹出一个问题对话框,给出信息”您是否确定要退出登录?“,并给出两个按钮Yes|No,用户点击Yes后,关闭登录界面,用户点击No后,关闭对话框,继续执行登录功能

要求:基于属性版和基于静态成员函数版至少各用一个 

main文件:

#include "work2.h"
#include "second.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    work2 w;
    w.show();

    //实例化第二个界面
    Second s;
    //将跳转信号和对应的槽函数连接
    QObject::connect(&w,&work2::jump_Second_signal,&s,&Second::jump_Second_slot);

    return a.exec();
}

 第一个界面头文件:

#ifndef WORK2_H
#define WORK2_H

#include <QWidget>
#include <QMessageBox>

QT_BEGIN_NAMESPACE
namespace Ui { class work2; }
QT_END_NAMESPACE

class work2 : public QWidget
{
    Q_OBJECT

public:
    work2(QWidget *parent = nullptr);
    ~work2();

signals:
    void jump_Second_signal();//声明跳转第二个界面的信号


private slots:
    void on_login_button_clicked();

    void on_cancel_button_clicked();

private:
    Ui::work2 *ui;
};
#endif // WORK2_H

第一个界面源文件:

#include "work2.h"
#include "ui_work2.h"

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

    //设置窗口图标
    this->setWindowIcon(QIcon(":/photograph/picture/starry sky.jpg"));
    //纯净窗口
    this->setWindowFlag(Qt::FramelessWindowHint);

    //去掉空白
    this->setAttribute(Qt::WA_TranslucentBackground);

    //设置 占位
    ui->user_edit->setPlaceholderText("账号/手机号");
    //设置 占位
    ui->passwd_edit->setPlaceholderText("密码");
    //设置显示模式 (密码)
    ui->passwd_edit->setEchoMode(QLineEdit::Password);

}

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

//登录按钮槽函数
void work2::on_login_button_clicked()
{
    if(ui->user_edit->text() == "wang1111" && ui->passwd_edit->text() == "123456")
    {
        //弹出信息对话框,表示登录成功
        QMessageBox::information(this,"提示","登录成功");
        //关闭登录窗口
        this->close();
        //跳转到第二个界面
        emit jump_Second_signal();
    }
    else
    {
        //弹出错误对话框
        QMessageBox Critical_msg(QMessageBox::Critical,"错误","账号和密码不匹配,是否重新登录",QMessageBox::Yes | QMessageBox::No);
        //调用exec函数弹出对话框
        int ret = Critical_msg.exec();
        //根据不同选择执行不同功能
        if(ret == QMessageBox::Yes)
        {
            //清除密码框的内容
            ui->passwd_edit->clear();
        }
        else if(ret == QMessageBox::No)
        {
            //关闭登录界面
            this->close();
        }

    }
}

//取消按钮槽函数
void work2::on_cancel_button_clicked()
{
    //弹出问题对话框
    int ret = QMessageBox::question(this,"问题","您是否确定要退出登录?", QMessageBox::Yes | QMessageBox::No);
    //根据不同选择执行不同的功能
      if(ret == QMessageBox::Yes)
      {
         //关闭登录界面
          this->close();
      }
      else if(ret == QMessageBox::No)
      {
          //回到登录界面,不做任何处理
      }
}

第二个界面头文件:

#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_Second_slot();//跳转到第二个界面的槽函数声明

private:
    Ui::Second *ui;
};

#endif // SECOND_H

第二个界面的源文件:

#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_Second_slot()
{
    //显示第二个界面
    this->show();
}

qss语句:

*{	
	background-color: rgb(255, 255, 255);
}

QFrame#frame{
	
	
	border-image: url(:/photograph/picture/liuying.jpg);
}

#frame_2{
	
	background-color: rgba(153, 153, 153, 120);
}

QLabel#label_1{
	border-radius:30px;
	background-color: rgba(144, 144, 144, 120);
}
#label_2{
	background:transparent; /*完全透明*/
	color: rgba(128, 255, 106, 120);
	font: 18pt "等线";
}

QLineEdit{
	background:transparent; /*完全透明*/
	border:none;  /*无边框*/
	border-bottom: 1px solid rgba(255, 255, 255, 120);/*显示下边框*/
	color: rgba(255, 255, 255, 120);
	font: 14pt "等线";
}

QPushButton#login_button{
	border-radius:10px;
	color: rgba(255, 255, 255, 120);
	font: 14pt "等线";
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(96, 161, 215, 255), stop:1 rgba(255, 255, 255, 255));
}
QPushButton#login_button:hover{  /*鼠标移动*/
	border-radius:10px;
	color: rgba(255, 255, 255, 120);
	font: 14pt "等线";
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(130, 161, 215, 255), stop:1 rgba(255, 255, 255, 255));
}
QPushButton#login_button:pressed{  /*鼠标按压*/
	border-radius:10px;
	color: rgba(255, 255, 255, 120);
	font: 14pt "等线";
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(96, 161, 215, 255), stop:1 rgba(255, 255, 255, 255));
	padding-top:5px;
	padding-left:5px;
}

QPushButton#cancel_button{
	border-radius:10px;
	color: rgba(255, 255, 255, 120);
	font: 14pt "等线";
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(96, 161, 215, 255), stop:1 rgba(255, 255, 255, 255));
}
QPushButton#cancel_button:hover{  /*鼠标移动*/
	border-radius:10px;
	color: rgba(255, 255, 255, 120);
	font: 14pt "等线";
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(130, 161, 215, 255), stop:1 rgba(255, 255, 255, 255));
}
QPushButton#cancel_button:pressed{  /*鼠标按压*/
	border-radius:10px;
	color: rgba(255, 255, 255, 120);
	font: 14pt "等线";
	
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(96, 161, 215, 255), stop:1 rgba(255, 255, 255, 255));
	padding-top:5px;
	padding-left:5px;
}

#quit_button{
	font: 28pt "等线";
background:transparent;/*完全透明*/
	color: rgb(255, 255, 255);
}
#quit_button:hover{
	color: rgb(255, 255, 255);
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(96, 161, 215, 255), stop:1 rgba(255, 255, 255, 255));
}

#min_button{
	font: 28pt "等线";
background:transparent;/*完全透明*/
	color: rgb(255, 255, 255);
}
#min_button:hover{
	color: rgb(255, 255, 255);
	background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(96, 161, 215, 255), stop:1 rgba(255, 255, 255, 255));
}

#checkBox_1{
	font: 9pt "等线";
background:transparent;/*完全透明*/
	color: rgb(255, 255, 255);
}

#checkBox2{
	font: 9pt "等线";
background:transparent;/*完全透明*/
	color: rgb(255, 255, 255);
}

Qt_day4作业1

 思维导图:

举报

相关推荐

0 条评论