QQ界面
widget.cpp
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
//设置框体的大小和颜色
this->setFixedSize(350,500);
this->setStyleSheet("background-color:#e5f0ff;");
//创建一个LineEdit edit1
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);
//创建一个LineEdit edit2
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);
//设置RadioButton
QRadioButton *rbutton = new QRadioButton("已阅读并同意服务协议和QQ隐私保护指引", this);
rbutton->move(edit2->x()+10,edit2->y()+edit2->height()+20);
connect(rbutton,&QRadioButton::clicked,this,&Widget::rbutton_clicked_slot);
//创建按钮btn1
btn1 = new QPushButton("登录",this);
//设置btn的样式位置大小
btn1->setStyleSheet("color:white;background-color:skyblue;border-radius:15px;font-size: 14px;");
btn1->resize(130,40);
btn1->move(edit1->x(),rbutton->y()+rbutton->height()+20);
//绑定点击事件槽函数
connect(btn1,&QPushButton::clicked,this,&Widget::btn1_clicked_slot);
//创建按钮btn2
btn2 = new QPushButton("取消",this);
//设置btn的样式位置大小
btn2->setStyleSheet("color:white;background-color:skyblue;border-radius:15px;font-size: 14px;");
btn2->resize(130,40);
btn2->move(btn1->width()+btn1->x()+20,rbutton->y()+rbutton->height()+20);
//绑定点击事件
connect(btn2,&QPushButton::clicked,this,&Widget::btn2_clicked_slot);
//定义3个label
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(":/picture/head.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()
{
}
//btn1的点击事件槽函数
void Widget::btn1_clicked_slot(){
//点击之后判断账号密码是否一致,一致则弹出登录成功并给出登录按钮,点击后弹出另一个窗口
//当账号和密码不匹配是,给出错误对话框,给出信息为账号和密码不匹配,是否重新登录,
//并提供两个按钮 Yes|No,如果用户点击了Yes,则清空密码框后,继续登录。如果用户点击的取消,则关闭登录界面
QString get_edit1 = edit1->text();
QString get_edit2 = edit2->text();
qDebug()<<get_edit2;
if(get_edit1==nullptr||get_edit2==nullptr){
QMessageBox::question(this,
"提示",
"输入不能为空",
QMessageBox::Ok
);
}else if(get_edit1==get_edit2 ){
QMessageBox box(QMessageBox::Information,
"提示",
"登录成功!",
QMessageBox::Ok,
this
);
box.setButtonText(QMessageBox::Ok,"确认");
int btn = box.exec();
if(btn==QMessageBox::Ok){
this->close();
emit jump();
}
}else{
int btn = QMessageBox::information(this,
"提示",
"账号和密码不匹配,是否重新登录",
QMessageBox::Yes|QMessageBox::No,
QMessageBox::No
);
if(btn == QMessageBox::Yes){
edit1->clear();
edit2->clear();
}else if(btn == QMessageBox::No){
this->close();
}
}
}
//btn2的点击事件槽函数
void Widget::btn2_clicked_slot(){
int btn = QMessageBox::question(this,
"提示",
"是否退出登录",
QMessageBox::Yes|QMessageBox::No,
QMessageBox::No
);
if(btn == QMessageBox::Yes){
this->close();
}else if(btn == QMessageBox::No){
}
}
void Widget::rbutton_clicked_slot(){
btn1->setStyleSheet("color:white;background-color:#0099FF;border-radius:15px;font-size: 14px;");
btn2->setStyleSheet("color:white;background-color:#0099FF;border-radius:15px;font-size: 14px;");
}
second.cpp
#include "second.h"
#include "ui_second.h"
Second::Second(QWidget *parent) :
QWidget(parent),
ui(new Ui::Second)
{
ui->setupUi(this);
}
Second::~Second()
{
delete ui;
}
void Second::jump_slot(){
this->show();
}
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
Second s;
//绑定w的jump发出的信号与Second中的槽
QObject::connect(&w,&Widget::jump,&s,&Second::jump_slot);
return a.exec();
}
wigdet.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include<QTextEdit>
#include <QPainter>
#include <QRadioButton>
#include <QLabel>
#include <QComboBox>
#include <second.h> //添加second.h头文件
#include <QMessageBox>
#include<QDebug>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
public slots://槽
void btn1_clicked_slot();
void btn2_clicked_slot();
void rbutton_clicked_slot();
signals://信号
void jump();
private:
QLineEdit *edit1;
QLineEdit *edit2;
QPushButton *btn1;
QPushButton *btn2;
};
#endif // WIDGET_H
second.h
#ifndef SECOND_H
#define SECOND_H
#include <QWidget>
namespace Ui {
class Second;
}
class Second : public QWidget
{
Q_OBJECT
public:
explicit Second(QWidget *parent = nullptr);
~Second();
public slots:
//定义实现jump_slot信号函数
void jump_slot();
private:
Ui::Second *ui;
};
#endif // SECOND_H