#include "mywidget.h"
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
this->setWindowTitle("英雄联盟");
this->resize(862,486);
this->setFixedSize(862,486);
this->setWindowFlag(Qt::FramelessWindowHint);
this->setStyleSheet("background-color:rgb(80,110,115)");
QLabel *lab1=new QLabel(this);
lab1->resize(640,486);
QMovie *mv=new QMovie("D:\\23081C++\\pictrue\\pictrue\\1.gif");
lab1->setMovie(mv);
mv->start();
lab1->setScaledContents(true);
QLabel *lab2=new QLabel(this);
lab2->resize(50,50);
lab2->setPixmap(QPixmap("D:\\23081C++\\pictrue\\pictrue\\22.png"));
lab2->move(20,20);
lab2->setScaledContents(true);
QLabel * lab3=new QLabel(this);
lab3->resize(222,150);
lab3->setPixmap(QPixmap("D:\\23081C++\\pictrue\\pictrue\\2.png"));
lab3->move(640,0);
QLabel * lab4=new QLabel(this);
lab4->resize(20,20);
lab4->setPixmap(QPixmap("D:\\23081C++\\pictrue\\pictrue\\userName.jpg"));
lab4->move(680,300);
lab4->setScaledContents(true);
QLabel * lab5=new QLabel(this);
lab5->resize(20,20);
lab5->setPixmap(QPixmap("D:\\23081C++\\pictrue\\pictrue\\passwd.jpg"));
lab5->move(680,330);
lab5->setScaledContents(true);
QLineEdit *edit1=new QLineEdit(this);
edit1->move(700,300);
edit1->setPlaceholderText("账号");
QLineEdit *edit2=new QLineEdit(this);
edit2->move(700,330);
edit2->setPlaceholderText("密码");
edit2->setEchoMode(QLineEdit::Password);
QPushButton * btn1=new QPushButton(this);
btn1->resize(155,30);
btn1->move(680,360);
btn1->setText("登录");
btn1->setStyleSheet("background-color:orange;border-radius:10px");
QPushButton * btn2=new QPushButton(this);
btn2->resize(20,20);
btn2->move(842,0);
btn2->setText("x");
QPushButton * btn4=new QPushButton(this);
btn4->resize(20,20);
btn4->move(822,0);
btn4->setText("□");
QPushButton * btn3=new QPushButton(this);
btn3->resize(20,20);
btn3->move(802,0);
btn3->setText("-");
// 创建一个QLabel对象
QLabel *label = new QLabel(this);
label->setFixedSize(60, 60);
// 加载图片并调整尺寸
QPixmap pixmap("D:\\23081C++\\pictrue\\pictrue\\3.png");
pixmap = pixmap.scaled(label->size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
// 创建圆形mask,使用QPainter绘制
QPixmap roundPixmap(label->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());
// 将原始图片按照mask绘制到圆形pixmap上
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.drawPixmap(0, 0, pixmap);
// 将圆形pixmap设置为label的背景图像
label->setPixmap(roundPixmap);
label->move(720,200);
lab3->setScaledContents(true);
}
MyWidget::~MyWidget()
{
}
![](https://i-blog.csdnimg.cn/blog_migrate/9ae96194348c27ff81527465fa40ea4a.png)