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.运行效果图

无头部效果

二、思维导图

相关推荐
l1t9 分钟前
DeepSeek总结的DuckLake 入门
数据库
Joseph Cooper18 分钟前
RAG 与 AI Agent:智能体真的需要检索增强生成吗?
数据库·人工智能·ai·agent·rag·上下文工程
light blue bird22 分钟前
主子端台二分法任务汇总组件
前端·数据库·.net·桌面端winform
DevilSeagull1 小时前
MySQL(2) 客户端工具和建库
开发语言·数据库·后端·mysql·服务
小李来了!1 小时前
Navicate/plsql连接Oracle数据库教程
数据库·oracle
苍煜1 小时前
慢SQL优化实战教学
java·数据库·sql
zhaoyong2222 小时前
MySQL 存储过程中字符集与排序规则不匹配导致查询性能下降的解决方案
jvm·数据库·python
sinat_383437362 小时前
golang如何从Python转型Go开发_golang从Python转型Go开发攻略
jvm·数据库·python
远洪2 小时前
claude code 国内安装使用
数据库·mysql
雨辰AI2 小时前
SpringBoot3 + 人大金仓 V9 微服务监控实战|Prometheus+Grafana+SkyWalking 全链路监控
数据库·后端·微服务·grafana·prometheus·skywalking