您的位置:首页 > 新闻 > 会展 > 中国工程机械网的官网_东营房产信息网58同城_网站营销网_免费外链网盘

中国工程机械网的官网_东营房产信息网58同城_网站营销网_免费外链网盘

2024/10/10 2:02:38 来源:https://blog.csdn.net/qq_62608227/article/details/142766947  浏览:    关键词:中国工程机械网的官网_东营房产信息网58同城_网站营销网_免费外链网盘
中国工程机械网的官网_东营房产信息网58同城_网站营销网_免费外链网盘

优化登录框:

当用户点击取消按钮,弹出问题对话框,询问是否要确定退出登录,并提供两个按钮,yes|No,如果用户点击的Yes,则关闭对话框,如果用户点击的No,则继续登录
当用户点击的登录按钮,进行账号和密码的匹配,如果匹配成功,则弹出信息对话框,给出信息为,登录成功,并给出一个确定按钮,当用户点击该按钮后,关闭登录界面,弹出另一个界面
当账号和密码不匹配是,给出错误对话框,给出信息为账号和密码不匹配,是否重新登录,并提供两个按钮 Yes|No,如果用户点击了Yes,则清空密码框后,继续登录。如果用户点击的取消,则关闭登录界面
要求 :静态成员函数版本和对象版本各至少实现一个

代码展示

widget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QRadioButton>
#include <QMessageBox>
#include <QIcon>
#include <QLabel>
#include <QDebug>
#include <QPixmap>
#include <QPainter>
class Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();signals:void my_signal();void jump();
public slots:void my_slot();void cancel_click();
private:QLineEdit *edit1; // 账号编辑器QLineEdit *edit2; // 密码编辑器};
#endif // WIDGET_H
widget.cpp
#include "widget.h"Widget::Widget(QWidget *parent): QWidget(parent)
{setWindowTitle("QQ 登录");this->setFixedSize(480,672); // 设置界面尺寸this->setStyleSheet("background-color:#271938");// 头像图标QLabel *iconLabel = new QLabel(this);iconLabel->resize(120,120);iconLabel->setPixmap(QPixmap(":/picture/QQ.png"));iconLabel->setScaledContents(true);iconLabel->move(178, 100); // 设置头像位置//构造账号编辑器edit1 = new QLineEdit(this);edit1->resize(384,64);edit1->setStyleSheet("background-color:#37335b;color:#a8a2ae;font-size:25px;border-radius:10px");edit1->setAlignment(Qt::AlignCenter);edit1->setPlaceholderText("手机号/QQ号/邮箱");edit1->move(48,251);//密码编辑器edit2 = new QLineEdit(this);edit2->resize(384,64);edit2->setStyleSheet("background-color:#37335b;color:#a8a2ae;font-size:25px;border-radius:10px");edit2->setAlignment(Qt::AlignCenter);edit2->setEchoMode(QLineEdit::Password);edit2->setPlaceholderText("请输入QQ密码");edit2->move(48,edit1->y()+85);//单选框QRadioButton *circleRadioButton = new QRadioButton(this);circleRadioButton->setText("已阅读并同意服务协议和QQ隐私保护指引");circleRadioButton->setStyleSheet("color: #868285; font-size: 18px;");circleRadioButton->move(48, edit2->y() + 85);circleRadioButton->setChecked(false); // 默认未选中//登录框QPushButton *loginButton = new QPushButton("登录",this);loginButton->setStyleSheet("background-color: #23335a;color:#685e75;font-size: 22px; border-radius: 10px;");loginButton->resize(180, 57);loginButton->move(48,circleRadioButton->y()+40);connect(loginButton,&QPushButton::clicked,this,&Widget::my_slot);//取消框QPushButton *cancelButton = new QPushButton("取消",this);cancelButton->setStyleSheet("background-color: #23335a;color:#685e75;font-size: 22px; border-radius: 10px;");cancelButton->resize(180, 57);cancelButton->move(loginButton->x()+200,circleRadioButton->y()+40);connect(cancelButton,&QPushButton::clicked,this,&Widget::cancel_click);//connect(cancelButton,SIGNAL(clicked()),this,SLOT(close()));// 超链接标签QLabel *linkLabel = new QLabel(this);linkLabel->setText("扫码登录 | 更多选项");linkLabel->setOpenExternalLinks(true); // 允许打开外部链接linkLabel->setStyleSheet("color: #2c71da; font-size: 20px;"); // 设置字体颜色linkLabel->move(141, loginButton->y()+ 120); // 设置位置}Widget::~Widget()
{}void Widget::my_slot() {QString username = edit1->text(); // 获取账号输入QString password = edit2->text(); // 获取密码输入// 判断输入内容if (username.isEmpty() || password.isEmpty()) {// 提示用户输入不能为空QMessageBox::warning(this, "输入错误", "账号或密码不能为空!");} else if(username == password){// 这里可以添加更多的判断逻辑,例如验证账号和密码?QMessageBox::information(this, "登录成功", "欢迎," + username + "!登录成功!");this->close();emit jump();} else if(username != password){int btn = QMessageBox::warning(this, "输入错误", "账号或密码不正确!",QMessageBox::Yes|QMessageBox::No);if(btn == QMessageBox::No){this->close();}else if(btn == QMessageBox::Yes){edit2->clear();}}}void Widget::cancel_click()
{QMessageBox box(QMessageBox::Question,"退出","是否要确定退出登录",QMessageBox::Ok|QMessageBox::No,this);box.setButtonText(QMessageBox::Ok,"确定");box.setButtonText(QMessageBox::No,"取消");box.setDefaultButton(QMessageBox::No);int btn = box.exec();if(btn == QMessageBox::Ok){this->close();}}

运行结果

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

思维导图

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com