自由发挥应用场景实现一个登录窗口界面。
mywidget.cpp
#include "mywidget.h"MyWidget::MyWidget(QWidget *parent): QWidget(parent)
{//窗口相关设置this->setWindowTitle("原神启动");this->setWindowIcon(QIcon("C:\\Users\\17212\\Pictures\\pri\\p.jpg"));//去掉头部 设置纯净窗口//this->setWindowFlag(Qt::FramelessWindowHint);//设置窗口的大小this->resize(600,450);this->setStyleSheet("background-color:grey");//设置固定大小this->setFixedSize(600,450);//标签相关设置QLabel *lab1 = new QLabel(this);lab1->resize(600,200);lab1->setStyleSheet("background-color:rbg(240,255,128)");//动图类 QMovieQMovie *mv = new QMovie("C:\\Users\\17212\\Pictures\\pri\\R-C.gif");mv->setParent(this);//将动图设置到标签中lab1->setMovie(mv);//让动图动起来mv->start();lab1->setScaledContents(true);QLabel *lab2 = new QLabel(this);lab2->resize(35,35);lab2->move(160,230);//接收动图类 QMovieQMovie *mv1 = new QMovie("C:\\Users\\17212\\Pictures\\pri\\a.gif");//将动图设置标签中lab2->setMovie(mv1);//让动态动起来mv1->start();lab2->setScaledContents(true);QLabel *lab3 = new QLabel(this);lab3->resize(35,35);lab3->move(160,270);lab3->setPixmap(QPixmap("C:\\Users\\17212\\Pictures\\t\\Camera Roll\\Saved Pictures\\pictrue\\passwd.jpg"));lab3->setScaledContents(true);QLabel *lab4 = new QLabel(this);lab4->resize(70,40);lab4->move(510,400);lab4->setPixmap(QPixmap("C:\\Users\\17212\\Pictures\\pri\\mhy.jpg"));lab4->setScaledContents(true);QLabel *lab5 = new QLabel(this);lab5->resize(50,50);lab5->move(50,390);QMovie *mv2 = new QMovie("C:\\Users\\17212\\Pictures\\pri\\c.gif");lab5->setMovie(mv2);mv2->start();lab5->setScaledContents(true);//行编辑器相关设置QLineEdit *edit1 = new QLineEdit(this);edit1->move(200,230);edit1->resize(270,35);edit1->setPlaceholderText("UID/QQ号/手机号码/邮箱");QLineEdit *edit2 = new QLineEdit(this);edit2->move(200,270);edit2->resize(270,35);edit2->setPlaceholderText("密码");edit2->setEchoMode(QLineEdit::Password);//按钮相关设置QPushButton *btn = new QPushButton("登录",this);btn->move(160,310);btn->resize(310,45);btn->setStyleSheet("background-color:rgb(30,200,250)");
}MyWidget::~MyWidget()
{
}
mywidget.h
#ifndef MYWIDGET_H
#define MYWIDGET_H#include <QWidget>
#include <QPushButton>
#include <QMovie>
#include <QLineEdit>
#include <QLabel>
class MyWidget : public QWidget
{Q_OBJECTpublic:MyWidget(QWidget *parent = nullptr);~MyWidget();
};
#endif // MYWIDGET_H