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

无头部效果

二、思维导图

相关推荐
hans汉斯10 小时前
【软件工程与应用】平移置换搬迁系统设计与实现
数据库·人工智能·系统架构·软件工程·汉斯出版社·软件工程与应用
gugugu.10 小时前
Redis List类型完全指南:从原理到实战应用
数据库·redis·list
Hello.Reader10 小时前
Flink SQL ALTER 语句在线演进 Table/View/Function/Catalog/Model
数据库·sql·flink
白学还是没白学?10 小时前
exec db docker from A to B
数据库·docker·容器
云老大TG:@yunlaoda36011 小时前
腾讯云国际站代理商TCCC的技术适配服务包括哪些内容?
数据库·云计算·腾讯云
元气满满-樱11 小时前
MySql部署多实例
数据库·mysql·adb
LFly_ice11 小时前
PostgreSql 常用聚合函数
数据库·postgresql
TH_111 小时前
12、新增数据到DB的几大方案
数据库
欢喜躲在眉梢里11 小时前
基于 openFuyao 社区的无硬件 UB 开发实战指南
运维·数据库·人工智能·vscode·ai·开发工具·go开发