widget.cpp
widegt.h
.pro
main.cpp
一个仿QQ登录界面
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
this->setFixedSize(350,500);
this->setStyleSheet("background-color:#e5f0ff;");
QLineEdit *edit1 = new QLineEdit(this);
edit1->setStyleSheet("background-color:white;font-size: 20px;color:black;");
edit1->resize(286,45);
edit1->move(35,186);
edit1->setPlaceholderText("输入QQ号");
edit1->setAlignment(Qt::AlignCenter);
QLineEdit *edit2 = new QLineEdit(this);
edit2->setStyleSheet("background-color:white;color:black;font-size: 20px;");
edit2->resize(286,45);
edit2->move(edit1->x(),edit1->y()+edit1->height()+20);
edit2->setPlaceholderText("输入QQ密码");
edit2->setAlignment(Qt::AlignCenter);
edit2->setEchoMode(QLineEdit::Password);
QRadioButton *rbutton = new QRadioButton("已阅读并同意服务协议和QQ隐私保护指引", this);
rbutton->move(edit2->x()+10,edit2->y()+edit2->height()+20);
QPushButton *but1 = new QPushButton("登录",this);
but1->setStyleSheet("color:white;background-color:skyblue;border-radius:15px;font-size: 14px;");
but1->resize(286,40);
but1->move(edit1->x(),rbutton->y()+rbutton->height()+20);
QLabel *label1 = new QLabel("扫码登录",this);
QLabel *label2 = new QLabel("|",this);
QLabel *label3 = new QLabel("更多选项",this);
label1->move(175-60,445);
label1->setStyleSheet("color:blue");
label2->move(175,label1->y());
label2->setStyleSheet("color:grey");
label3->move(175+10,label1->y());
label3->setStyleSheet("color:blue");
QLabel *iconLabel = new QLabel(this);
QPixmap pixmap("G:/Qt/20240701/QT/day1/头像.jpg"); // 请确保有一个图标文件
pixmap = pixmap.scaled(100, 100, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); // 调整图标大小
iconLabel->setPixmap(pixmap);
iconLabel->setFixedSize(100, 100);
iconLabel->setStyleSheet("border-radius: 45px; border: 2px solid white;"); // 设置圆形和边框
iconLabel->setAlignment(Qt::AlignCenter);
iconLabel->move(176-50,70); // 设置头像位置
}
Widget::~Widget()
{
}
效果图