qt day1

1.应用场景实现一个登录窗口界面。

代码实现:

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

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
{
//1.-----------创建一个窗口-------------//
    //设置纯净窗口
    this->setWindowFlag(Qt::FramelessWindowHint);
    //设置窗口图标
    this->setWindowIcon(QIcon("C:\\Users\\18225\\Desktop\\picture\\logo"));
    //设置窗口颜色
    this->setStyleSheet("background-color:rgb(18,18,18)");
    //设置大小
    this->resize(340,600);
    //设置窗口固定大小
    this->setFixedSize(340,600);

//2.-----------设置背景版-------------//
    //实例化一个标签类
    QLabel *lab1 = new QLabel(this);  //指向父类
    //这是标签(背景板)大小
    lab1->resize(340,240);
    //设置背景版颜色
    lab1->setStyleSheet("background-color:rgb(18,18,18)");
    //将动图加载到窗口内
    QMovie *mv = new QMovie("C:\\Users\\18225\\Desktop\\picture\\spo.gif");
    //将动图设置到标签中
    lab1->setMovie(mv);
    //启动动图
    mv->start();
    //将动图设置自适应标签大小
    lab1->setScaledContents(true);

    //为标签设置文本
    QLabel *lab2 = new QLabel(this);
    lab2->resize(35,40);
    lab2->move(160,500);
    lab2->setText("登录");
    lab2->setStyleSheet("background-color:rgb(255,255,255)");
    lab2->setStyleSheet("color:white");

    QLabel *lab3 = new QLabel(this);
    lab3->move(75,200);
    lab3->resize(200,50);
    lab3->setText("通过Spotify,免费畅听百万歌曲。");
    lab3->setStyleSheet("background-color:rgb(255,255,255)");
    lab3->setStyleSheet("color:white");


//    QLabel *lab4 = new QLabel(this);
//    lab4->move(10,355);
//    lab4->resize(35,40);
//    lab4->setPixmap(QPixmap("C:\\Users\\18225\\Desktop\\picture\\gogo"));
//    lab4->setScaledContents(true);


//3.-----------设置按钮-------------//
    QPushButton *btn1 = new QPushButton("免费注册",this);
    btn1->move(20,300);
    btn1->resize(300,50);
    btn1->setStyleSheet("background-color:rgb(30,215,96);border-radius:20px;color:black");

    QPushButton *btn2 = new QPushButton("使用 Google 账号继续",this);
    btn2->move(20,360);
    btn2->resize(300,50);
    btn2->setStyleSheet("background-color:#000000;border-radius:20px;color:white");

    QPushButton *btn3 = new QPushButton("使用 Facebook 账号继续",this);
    btn3->move(20,420);
    btn3->resize(300,50);
    btn3->setStyleSheet("background-color:#000000;border-radius:20px;color:white");

}

MyWidget::~MyWidget()
{
}

效果:

相关推荐
JetComXCpp2 小时前
给 Win32 窗口加上毛玻璃效果——纯 D3D11 实现,零依赖
c++
ysa0510303 小时前
【板子】二分答案(最大最小?)
c++·笔记·算法·板子
stolentime4 小时前
SP8549 MAIN75 - BST again题解
c++·算法·二叉树·深度优先·图论·记忆化搜索·组合数学
ziguo11224 小时前
C/C++ 错误处理全解:从 errno 到 C++ 异常
linux·c语言·c++·windows·visual studio
stolentime5 小时前
AT_pakencamp_2020_day1_k Gcd of Sum题解
c++·算法
2601_956121975 小时前
map_计蒜客T1271 完美K倍子数组
c++·算法
王维同学6 小时前
IFEO Debugger、VerifierDlls 与 SilentProcessExit 配置
c++·windows·安全·注册表
小保CPP6 小时前
OpenCV C++计算多边形的最大内切圆
c++·人工智能·opencv·计算机视觉
lueluelue477 小时前
八股临时总结
c++
Quz8 小时前
QML 基础按钮:Button、RoundButton 与 DelayButton
qt