DAY51

 Widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
#include <QCheckBox>
#include <QComboBox>
#include <QObject>
#include <QDebug>
#include "form.h"
#include <QMessageBox>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

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


private slots:

    void on_btn2_clicked(QLineEdit * edit1,QLineEdit * edit2);

    void on_btn1_clicked();

    void on_btn3_clicked();

signals:
    void jump();


private:
    Ui::Widget *ui;
    Form *s1;

    Form *th;
};
#endif // WIDGET_H

form.h

#ifndef FORM_H
#define FORM_H

#include <QWidget>

namespace Ui {
class Form;
}

class Form : public QWidget
{
    Q_OBJECT

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

private:
    Ui::Form *ui;

public:
    void jump_slot();
};

#endif // FORM_H

main.cpp

#include "widget.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    return a.exec();
}

form.cpp

#include "form.h"
#include "ui_form.h"

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

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


void Form::jump_slot()
{
    this->show();
}

widget.cpp

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

Widget::Widget(QWidget *parent)
    : QWidget(parent)

{
    ui->setupUi(this);
    s1 = new Form;
    connect(this,&Widget::jump,s1,&Form::jump_slot);


    qDebug() << this->size();   //获取当前界面的尺寸
    this->resize(QSize(500,400));     //重新使用匿名对象作为函数参数设置当前组件的尺寸
    this->setMaximumSize(1000,800);   //设置最大尺寸
    this->setMinimumSize(200,100);    //设置最小尺寸
    this->setFixedSize(600,400);     //设置固定尺寸

    qDebug() << this->windowTitle();    //获取当前组件的窗口标题
    this->setWindowTitle("221#223社畜登录框");      //设置窗口标题
    this->setWindowIcon(QIcon("C:\\Users\\Administrator\\Desktop\\QQ.png"));    //设置窗口图标
    this->setStyleSheet("background-color:skyblue;");    //设置窗口样式表
    this->setWindowOpacity(1);       //设置窗口透明度
    //this->setWindowFlag(Qt::FramelessWindowHint);    //去掉窗口头部



    //使用无参构造函数,构造一个按钮
    QPushButton *btn1 = new QPushButton;
    //btn1->show();      //有该函数,但是没有父组件,只能单独存在
    btn1->setParent(this);      //将当前界面作为父组件
    btn1->setText("找回密码");       //设置按钮上的文本内容
    qDebug()<<btn1->size();     //获取按钮尺寸
    btn1->resize(80,30);       //重新设置按钮组件尺寸
    qDebug()<<btn1->size();
    btn1->setIcon(QIcon("C:\\Users\\Administrator\\Desktop\\QQ.png"));   //设置图标
    btn1->move(150,350);       //移动按钮组件
    btn1->setStyleSheet("background-color:skyblue; border-radius:10px; ");    //设置按钮样式表
    //btn1->setEnabled(false);              //设置不可用状态



    //构造一个按钮,构造是直接指定父组件
    QPushButton *btn2 = new QPushButton(this);
    btn2->setText("登录");
    btn2->resize(btn1->size());
    btn2->move(btn1->x() + 110,btn1->y());
    btn2->setIcon(QIcon("C:\\Users\\Administrator\\Desktop\\QQ.png"));
    btn2->setStyleSheet("background-color:skyblue; border-radius:10px; ");
    //btn2->setEnabled(false);



    //构造按钮时直接给定文本内容以及父组件
    QPushButton *btn3 = new QPushButton(this);
    btn3->resize(btn1->size());
    btn3->setText("退出");
    btn3->move(btn2->x() + 110,btn2->y());
    btn3->setIcon(QIcon("C:\\Users\\Administrator\\Desktop\\QQ.png"));
    btn3->setStyleSheet("background-color:skyblue; border-radius:10px; ");
    //btn3->setEnabled(false);

/*
   //构造按钮时直接给定图标、文本内容、父组件
    QPushButton *btn4 = new QPushButton(QIcon("C:\\Users\\Administrator\\Desktop\\QQ.png"),"选项",this);
    btn4->move(btn3->x() + 150,btn3->y());
    btn4->setStyleSheet("background-color:skyblue; border-radius:10px; ");
    btn4->setEnabled(false);
*/


    //构造一个行编辑器对象,并指定父组件
    QLineEdit *edit1 = new QLineEdit(this);
    edit1->resize(250,30);
    edit1->move(btn1->x() + 50,btn1->y() - 150);
    edit1->setStyleSheet("background-color:skyblue;");
    //edit1->setEchoMode(QLineEdit::Password);   //设置回显模式
    edit1->setMaxLength(10);
    edit1->setPlaceholderText("社畜账号/手机/邮箱");
    //edit1->setText("*******");   //设置默认文本
    //edit1->setAlignment(Qt::AlignCenter);   //文本内容居中
    //QComboBox *cb1 = new QComboBox(this);




    //构造一个行编辑器,给定初始文本,并指定父组件
    //QLineEdit *edit2 = new QLineEdit("*****",this);



    QLineEdit *edit2 = new QLineEdit(this);
    edit2->resize(250,30);
    edit2->move(btn1->x() + 50,btn1->y() - 100);
    edit2->setStyleSheet("background-color:skyblue;");
    edit2->setEchoMode(QLineEdit::Password);   //设置回显模式
    edit2->setMaxLength(15);
    edit2->setPlaceholderText("******");


    //实例化一个标签,并给定初始文本内容,并指定父组件
    QLabel *lab1 = new QLabel("账号:",this);
    lab1->resize(40,30);
    lab1->setStyleSheet("background-color:skyblue;");
    lab1->move(btn1->x(),btn1->y() - 150);



    QLabel *lab2 = new QLabel("密码:",this);
    lab2->resize(40,30);
    lab2->setStyleSheet("background-color:skyblue;");
    lab2->move(btn1->x(),btn1->y() - 100);


    QLabel *lab3 = new QLabel(this);
    lab3->resize(600,200);
    lab3->setStyleSheet("background-color:white;");
    lab3->move(0,btn1->y() - 400);
    lab3->setPixmap(QPixmap("C:\\Users\\Administrator\\Desktop\\QQ截图20230915200445.png"));
    lab3->setScaledContents(true);





    QCheckBox *chbox1 = new QCheckBox("自动登录",this);
    chbox1->move(btn1->x() + 40,btn1->y() - 50);


    QCheckBox *chbox2 = new QCheckBox("记住密码",this);
    chbox2->move(btn1->x() + 180,btn1->y() - 50);






}

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

void Widget::on_btn2_clicked(QLineEdit * edit1,QLineEdit * edit2)
{
    //登录失败
    if(edit1->text()!="admin"&&edit2->text()!="123456")
    {
        //调用构造函数实例化对象
        QMessageBox box(QMessageBox::Critical,//图标
                        "错误",//对话框标题
                        "账号密码不匹配,是否重新登录",//对话框文本
                        QMessageBox::Yes|QMessageBox::No,//提供的按钮
                        this);//父组件
        box.setDefaultButton(QMessageBox::Yes);
        box.setButtonText(QMessageBox::Yes,"OK");
        box.setButtonText(QMessageBox::No,"cancel");
        //调用exec函数运行对话框
        int ret = box.exec();
        //对结果进行判断
        if(ret==QMessageBox::Yes)
        {
            //清空内容
            edit1->clear();
        }
        else
        {
            //关闭界面
            this->close();
        }
    }
    //登录成功
    else
    {
        //调用构造函数实例化对象
        QMessageBox box(QMessageBox::NoIcon,//图标
                        " ",//对话框标题
                        "登录成功",//对话框文本
                        QMessageBox::Ok,//提供的按钮
                        this);//父组件
        box.exec();//运行对话框
        emit jump();//跳转界面
        this->close();//关闭当前界面
    }

}

//退出按钮
void Widget::on_btn3_clicked()
{
    int ret=QMessageBox::warning(this,
                         "警告",
                         "是否确定要退出登录",
                         QMessageBox::Yes | QMessageBox::No,
                         QMessageBox::No);

    //对结果进行判断如果点yes则关闭
    if(ret==QMessageBox::Yes)
    {
        this->close();//关闭界面
    }
}

void Widget::on_btn1_clicked()
{

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

也许t

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值