day2Qt作业

#ifndef MYWIDGET_H
#define MYWIDGET_H


#include <QWidget>
#include <QDebug>
#include<QIcon>
#include<QLabel>
#include<QMovie>
#include<QLineEdit>
#include<QPushButton>
QT_BEGIN_NAMESPACE
namespace Ui { class MyWidget; }
QT_END_NAMESPACE

class MyWidget : public QWidget
{
    Q_OBJECT

public:
    MyWidget(QWidget *parent = nullptr);
    ~MyWidget();
public slots:
    void edit_Slots();
    void btn_Slots();


private:
    Ui::MyWidget *ui;
    QLabel *lab1;
    QLabel *lab2;
    QLabel *lab3;
    QLineEdit *edit1;
    QLineEdit *edit2;
    QPushButton *btn;
};
#endif // MYWIDGET_H

 

#include "mywidget.h"
#include "ui_mywidget.h"

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

    this->resize(540,415);//窗口大小
    this->setFixedSize(540,415);//固定窗口大小
    this->setWindowTitle("QQ");//标题
    this->setWindowIcon(QIcon("E:\\hqyjapp\\QT\\pictrue\\pictrue\\qq.png"));//图标
    this->setStyleSheet("background-color:white");//图标
   // this->setWindowFlag(Qt::FramelessWindowHint);//去头

    lab1 = new QLabel(this);//设置标签
    lab1->resize(540, 160);//标签大小
    QMovie *mv = new QMovie("E:\\hqyjapp\\QT\\pictrue\\pictrue\\qq2.gif");//接收动图
    lab1->setMovie(mv);//将动图放入标签
    mv->start();//让动图动起来
    lab1->setScaledContents(true);//自动适应大小


    lab2 = new QLabel(this);//设置标签2
    lab2->resize(30,30);//标签大小
    lab2->move(120,210);//标签移动位置
    lab2->setPixmap(QPixmap("E:\\hqyjapp\\QT\\pictrue\\pictrue\\wodepeizhenshi.png"));//将图片放入标签
    lab2->setScaledContents(true);//自动适应大小

    lab3 = new QLabel(this);//设置标签3
    lab3->resize(30,30);
    lab3->move(120, 260);
    lab3->setPixmap(QPixmap("E:\\hqyjapp\\QT\\pictrue\\pictrue\\passwd.jpg"));
    lab3->setScaledContents(true);


    edit1 = new QLineEdit(this);//设置行编辑器
    edit1->resize(275,30);//行编辑器大小
    edit1->move(155,210);//移动行编辑器位置
    edit1->setPlaceholderText("QQ号/手机号/邮箱");//行编辑器占位


    edit2 = new QLineEdit(this);
    edit2->resize(275,30);
    edit2->move(155,260);
    edit2->setPlaceholderText("密码");//行编辑器占位
    edit2->setEchoMode(QLineEdit::Password);//行编辑器密码模式显示


    btn = new QPushButton("登录",this);//按钮组件
    btn->resize(300,45);//按钮组件大小
    btn->move(120,345);//按钮组件移动位置
    //按钮背景色,边框倒角,字体颜色
    btn->setStyleSheet("background-color:red;border-radius:5px;color:white");
    btn->setEnabled(false);
    connect(this->edit1,&QLineEdit::textChanged,this,&MyWidget::edit_Slots);
    connect(this->edit2,&QLineEdit::textChanged,this,&MyWidget::edit_Slots);
    connect(this->btn,&QPushButton::clicked,this,&MyWidget::btn_Slots);

}

void MyWidget::btn_Slots()
{
    if(this->edit1->text()=="admin" && this->edit2->text()=="123456")
    {
        qDebug() << "登录成功";
        this->close();
    }
    else
    {
        qDebug() << "登录失败,账号或密码错误";
        this->edit1->clear();
        this->edit2->clear();
    }
}
void MyWidget::edit_Slots()
{
    QString s1=this->edit1->text();
    QString s2=this->edit2->text();
    if(s1.length()>=5 && s2.length()>=6 )
    {
        this->btn->setStyleSheet("background-color:rgb(8,189,253)");
        this->btn->setEnabled(true);

    }
    else if(s1.length()<5 || s2.length()<6  )
    {
      this->btn->setStyleSheet("background-color:red");
      this->btn->setEnabled(false);
    }


}

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值