QT day2 作业

头文件

cpp 复制代码
#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

源文件

cpp 复制代码
#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("D:\\QT\\pictrue\\pictrue\\qq.png"));
    //图标颜色
    this->setStyleSheet("background-color:white");
    
    //设置标签    
    lab1 = new QLabel(this);
    //设置标签大小
    lab1->resize(540, 160);
    //接收动图
    QMovie *mv = new QMovie("D:QT\\pictrue\\pictrue\\qq2.gif");
    //将动图放入标签
    lab1->setMovie(mv);
    //让动图动起来
    mv->start();
    //自动适应大小
    lab1->setScaledContents(true);
 
    //设置标签2
    lab2 = new QLabel(this);
    //标签大小
    lab2->resize(30,30);
    //标签移动位置
    lab2->move(120,210);
    //将图片放入标签
    lab2->setPixmap(QPixmap("D:QT\\pictrue\\pictrue\\wodepeizhenshi.png"));
    //自动适应大小
    lab2->setScaledContents(true);
 
    //设置标签
    lab3 = new QLabel(this);
    lab3->resize(30,30);
    lab3->move(120, 260);
    lab3->setPixmap(QPixmap("D: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(125,18,179)");
        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;
}
相关推荐
kimnoic6 小时前
Python数据库学习心得:SQLite、MySQL、PostgreSQL优缺点
开发语言·python
必须得开心呀7 小时前
python编写带界面的软件,需要安装哪些插件
开发语言·python
沫璃染墨9 小时前
《Qt从零入门系列(十三):QSS样式表详解——从选择器与层叠规则到控件美化实战》
开发语言·css·c++·qt·ui·qt6.3·qss
达子6669 小时前
RUST 图解 第 3 章:通用编程概念(Common Programming Concepts)
开发语言·算法·rust
道尔柯南10 小时前
C++ 面向对象编程入门:类和对象(上)
开发语言·c++·算法
楠楠子呀10 小时前
英语、西语、阿语客户各开一个口:多语言获客的分流方案
开发语言·javascript·ecmascript·跨境电商·whatsapp·营销工具
tachibana210 小时前
使用for range 的时候,它的地址会发生变化吗?
开发语言·后端·golang·go·语法
临床数据科学和人工智能兴趣组11 小时前
正则表达式的基础语法的基本符号
开发语言·人工智能·python·正则表达式·r语言·r语言-4.2.1·workbudyy
王中阳Go11 小时前
Go 后端转 AI:非科班怎么补?一张 3 列路线表(可保存)
开发语言·人工智能·后端·python·golang·大语言模型
geats人山人海11 小时前
java 4继承
java·开发语言