头文件
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
#include<QDebug>
#include<QIcon>
#include<QPushButton>
#include<QLineEdit>
#include<QLabel>
#include<QMovie>
#include<QCheckBox>
#include<QPainter>
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget(QWidget *parent = nullptr);
~MyWidget();
};
#endif // MYWIDGET_H
main函数
#include "mywidget.h"
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
this->resize(430, 330);
this->setWindowIcon(QIcon("D:/tp/qq.png"));
this->setWindowTitle("QQ");
//背景动图
QLabel *lab5 = new QLabel(this);
lab5->resize(430, 125);
QMovie *mv = new QMovie("D:/pic/1.gif");
lab5->setMovie(mv);
mv->start();
lab5->setScaledContents(true);
//账号框
QLineEdit *ed1 = new QLineEdit(this);
ed1->move(119,160);
ed1->setPlaceholderText("账号"); //设置占位
ed1->resize(230, 35);
ed1->setStyleSheet("; border-radius: 10px;padding:2px 4px;");
//企鹅图
QLabel *lab6 = new QLabel(this);
lab6->move(98, 170);
lab6->resize(21, 20);
lab6->setPixmap(QPixmap("D:/pic/qq.png"));
lab6->setScaledContents(true);
//密码框
QLineEdit *ed3 = new QLineEdit(this);
ed3->move(119, 200);
ed3->setPlaceholderText("密码"); //设置占位
ed3->resize(230, 35);
ed3->setEchoMode(QLineEdit::Password);
ed3->setStyleSheet("; border-radius: 10px;padding:2px 4px;");
//锁图片
QLabel *lab7 = new QLabel(this);
lab7->move(98, 210);
lab7->resize(21, 20);
lab7->setPixmap(QPixmap("D:/pic/key.png"));
lab7->setScaledContents(true);
//自动登录
QLabel *lab1 = new QLabel(this);
lab1->setText("自动登录");
lab1->move(123, 241);
//复选框
QCheckBox*box1 = new QCheckBox("Checkbox1", this);
box1->setChecked(true);
box1->move(105, 238);
box1->resize(21, 20);
//记住密码
QLabel *lab2 = new QLabel(this);
lab2->setText("记住密码");
lab2->move(204, 241);
// lab2->resize(20, 10);
//复选框
QCheckBox*box2 = new QCheckBox("Checkbox2", this);
box2->setChecked(true);
box2->move(186, 238);
box2->resize(21, 20);
// //插入头像
// QLabel *lab3 = new QLabel(this);
// lab3->move(175, 80);
// lab3->resize(75, 75);
// QMovie *mv2 = new QMovie("D:/pic/R-C.gif");
// lab3->setMovie(mv2);
// mv2->start();
// lab3->setScaledContents(true);
QLabel *lab9 = new QLabel(this);
lab9->setFixedSize(75, 75);
QPixmap pixmap("D:/pic/kl.jpg");
pixmap = pixmap.scaled(lab9->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
QPixmap roundPixmap(lab9->size());
roundPixmap.fill(Qt::transparent);
QPainter painter(&roundPixmap);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::white);
painter.drawEllipse(roundPixmap.rect());
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.drawPixmap(0, 0,pixmap);
lab9->setPixmap(roundPixmap);
lab9->move(175, 80);
lab9->setScaledContents(true);
//注册账号
QLabel *lab4 = new QLabel(this);
lab4->setText("注册账号");
lab4->move(10, 300);
// lab2->resize(20, 10);
//登录
QPushButton *btn1 = new QPushButton;
btn1->setText("登录");
btn1->setParent(this); //指定父对象
btn1->resize(230, 35);
btn1->move(105, 265);
btn1->setStyleSheet("background-color: rgb(112,216,253); border-radius: 10px;padding:2px 4px;");
//找回密码
QPushButton *btn2 = new QPushButton(this);
btn2->setText("找回密码");
btn2->move(270, 237);
btn2->resize(66, 22);
//二维码图
QLabel *lab8 = new QLabel(this);
lab8->move(390, 292);
lab8->resize(29, 29);
lab8->setPixmap(QPixmap("D:/pic/ewm.png"));
lab8->setScaledContents(true);
}
MyWidget::~MyWidget()
{
}