9.7(QT.Day 1)

一、自由发挥登录窗口的应用场景,实现一个登录窗口界面

要求:每行代码都有注释

【需要用到的图片或者动图,自己去网上找】

1.mywidget.h代码

cpp 复制代码
#ifndef MYWIDGET_H
#define MYWIDGET_H

#include <QWidget>
#include <QIcon> //图标类
#include<QLabel> //标签类
#include<QMovie> //动图类
#include<QLineEdit> //行编辑器类
#include<QPushButton> //按钮类

class MyWidget : public QWidget
{
    Q_OBJECT

public:
    MyWidget(QWidget *parent = nullptr);
    ~MyWidget();
};
#endif // MYWIDGET_H

2.mywidget.cpp代码

cpp 复制代码
#include "mywidget.h"

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
{
    //-------------窗口相关设置----------------
    this->setWindowTitle("用户登录"); //1.窗口标题
    this->setWindowIcon(QIcon("C:\\Users\\33492\\Pictures\\Camera Roll\\图片\\jye.png")); //2.窗口图标
    this->resize(612,946); //3.重设窗口大小
    this->setFixedSize(612,946); //4.固定窗口大小
    //this->setWindowFlag(Qt::FramelessWindowHint); //5.隐藏头部
    this->setStyleSheet("background-color:white");

    //-------------标签相关设置----------------
    QLabel *lal1 = new QLabel(this);
    lal1->resize(612,430); //1.重设标签大小
    QMovie *mv = new QMovie("C:\\Users\\33492\\Pictures\\Camera Roll\\图片\\longmao.gif"); //2.实例化一个动图对象
    lal1->setMovie(mv); //3.将动图设置到标签中
    mv->start(); //4.让动图动起来
    lal1->setScaledContents(true); //5.动图自动适应标签大小


    QLabel *lal2 = new QLabel(this);
    lal2->move(56,512); //1.移动到标签位置的首坐标
    lal2->resize(60,60);//2.重设标签大小
    lal2->setPixmap(QPixmap("C:\\Users\\33492\\Pictures\\Camera Roll\\图片\\R-C.png")); //3.设置一个图标
    lal2->setScaledContents(true); //4.自动适应

    QLabel *lal3 = new QLabel(this);
    lal3->move(56,588); //1.移动到标签位置的首坐标
    lal3->resize(60,60);//2.重设标签大小
    lal3->setPixmap(QPixmap("C:\\Users\\33492\\Pictures\\Camera Roll\\图片\\R-C (1).png")); //3.设置一个图标
    lal3->setScaledContents(true); //4.自动适应


    //-------------行编译器相关设置----------------
    QLineEdit *lie1 = new QLineEdit(this);
    lie1->move(120,512); //移动到要设行编译器的首坐标
    lie1->resize(450,60); //重设行编译器大小
    lie1->setPlaceholderText("用户名"); //占位显示用户名

    QLineEdit *lie2 = new QLineEdit(this);
    lie2->move(120,588); //移动到要设行编译器的首坐标
    lie2->resize(450,60); //重设行编译器大小
    lie2->setPlaceholderText("设置密码"); //占位显示用户名
    lie2->setEchoMode(QLineEdit::Password);

    //-------------按钮设置----------------
    QPushButton *pb1 = new QPushButton("注册",this);
    pb1->move(56,822); //移动到要设按钮的首坐标
    pb1->resize(240,70);//重设按钮大小
    pb1->setStyleSheet("background-color:rgb(8,189,252);color:white;border-radius:5px");//设定按钮颜色形状

    QPushButton *pb2 = new QPushButton("登录",this);
    pb2->move(344,822); //移动到要设按钮的首坐标
    pb2->resize(240,70);  //重设按钮大小
    pb2->setStyleSheet("background-color:rgb(8,189,252);color:white;border-radius:5px");//设定按钮颜色形状

}

MyWidget::~MyWidget()
{
}

3.运行效果图

无头部效果

二、思维导图

相关推荐
杨云龙UP11 分钟前
Oracle 19c:RMAN Duplicate异机复制数据库实操_20260402
linux·运维·服务器·数据库·网络协议·tcp/ip·oracle
森G12 分钟前
40、对话框---------事件系统
c++·qt
刘~浪地球15 分钟前
Redis 从入门到精通(七):集合操作详解
数据库·chrome·redis
光泽雨16 分钟前
SQL分组Group By
数据库
我真会写代码30 分钟前
MySQL高频面试题(含详细解析):从基础到高级,备战面试不踩坑
数据库·mysql·面试
观远数据35 分钟前
未来3年企业数据分析的核心:基于自然语言的AI优先决策体系如何搭建
数据库·人工智能·数据分析
YummyJacky37 分钟前
Redis在项目中的应用
数据库·redis·缓存
qq_2837200541 分钟前
MySQL 8.0新特性高频面试题 30 道(超详细答案)
数据库·mysql·面试·mysql8·高频试题
wAEWQ6Ib743 分钟前
[拆解LangChain执行引擎]支持自然语言查询的长期存储
数据库·oracle·langchain
吴声子夜歌1 小时前
Node.js——操作MongoDB
数据库·mongodb·node.js