2023/12/8 作业

//登录失败

//

//登录成功

思维导图

作业

头文件

#ifndef WIDGET_H
#define WIDGET_H
 
#include <QWidget>
 
#include<QDebug>
 
#include<QIcon>
 
#include<QMovie>
 
#include<QLabel>
 
#include<QLineEdit>
 
#include<QPushButton>
class Widget : public QWidget
{
    Q_OBJECT
 
 
  public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    //信号函数
    signals:
    //设定信号函数
        void my_signals();
        //槽函数
    public slots:
        //关闭的槽函数
        void my_slots();
        //登录判定的槽函数
        void my_login();
//可以随时使用
private:
        //设定用户名
    QLineEdit  *username;
    //设定密码
   QLineEdit  *password;
   //设定登录成功
   QLabel *login_success;
   //设定登录失败
  QLabel *login_error;
};
#endif // WIDGET_H
===================================================================================

mian文件

#include "widget.h"
 
#include <QApplication>
 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    return a.exec();
}
=======================================================================================

widget文件

#include "widget.h"
 
Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    //固定界面大小
    this->setFixedSize(640,500);
    //设定界面背景颜色
   this->setStyleSheet("background-color:rgb(238,138,248)");
    //设定窗口图标
   this->setWindowIcon(QIcon(":/png/head.png"));
    //设定界面的名字
    this->setWindowTitle("聊天");
    //去界面的头
   this->setWindowFlag(Qt::FramelessWindowHint);
 
   //设定标题名字
    QLabel *name=new QLabel(this);
    //移动
    name->move(260,20);
    //大小
    name->resize(100,20);
    //名字
    name->setText("聊天系统");
    //绑定画布
    name->setScaledContents(true);
 
    //设定退出的按钮
    QPushButton *exit=new QPushButton(QIcon(":/png/exit.png"),"",this);
    //设定大小
    exit->resize(30,30);
    //移动按钮
    exit->move(600,10);
    //赋予exit按下鼠标的信号事件,触发my_slots槽函数
    connect(exit,SIGNAL(clicked()),this,SLOT(my_slots()));
 
 
//创建一个画布
QLabel *mo=new QLabel(this);
//设定移动的距离
mo->move(0,50);
//设定大小
mo->resize(640,150);
//获取动图地址
QMovie *movie=new QMovie(":/png/start.gif");
//将动图放入画布
mo->setMovie(movie);
//让动图动起来
movie->start();
//自动适应画布大小
mo->setScaledContents(true);
 
 
 
//在头位置加一个图标
QLabel *head=new QLabel(this);
//获取图标
head->setPixmap(QPixmap(":/png/hello.png"));
//移动图标
head->move(10,10);
//图标的大小
head->resize(30,30);
//自动适应画布大小
head->setScaledContents(true);
 
 
//在中间加一个背景图
    QLabel *label=new QLabel(this);
    //获取背景图地址
   label->setPixmap(QPixmap(":/png/look.jpg"));
   //移动背景图
   label->move(0,200);
   //设置背景图大小
    label->resize(640,300);
    //绑定画布
   label->setScaledContents(true);
 
  //用户名行编辑器框
   username=new QLineEdit(this);
   //设置行编辑器位置
  username->move(170,210);
    //设置行编辑器大小
  username->resize(285,40);
   //设置行编辑器样式
username->setStyleSheet("background-color:rgb(31,200,253);border-radius:10px");
  //设置行编辑器名字
username->setPlaceholderText("用户名");
 
 
 
//密码行编辑器框
password=new QLineEdit(this);
//设置行编辑器位置
password->move(170,270);
//设置行编辑器大小
password->resize(285,40);
//设置行编辑器样式
password->setStyleSheet("background-color:rgb(31,200,253);border-radius:10px");
//设置行编辑器名字
password->setPlaceholderText("密码");
//password加密格式
password->setEchoMode(QLineEdit::Password);
 
 
//设定注册按钮
QPushButton *login=new QPushButton(this);
//大小
login->resize(285,40);
//位置
login->move(170,330);
//颜色形状
login->setStyleSheet("background-color:rgb(31,200,253);border-radius:10px");
//名字
login->setText("注册");
 
//设定登录按钮
QPushButton *serch=new QPushButton(this);
//大小
serch->resize(285,40);
//位置
serch->move(170,390);
//颜色形状
serch->setStyleSheet("background-color:rgb(31,200,253);border-radius:10px");
//名字
serch->setText("登录");
//赋予serch登录按钮按下,并把它附上槽函数
connect(serch,&QPushButton::clicked,this,&Widget::my_login);
 
 
}
 
Widget::~Widget()
{
 
}
//设定关闭的槽函数
void Widget::my_slots(){
    this->close();
}
//设定对登录的槽函数
void Widget::my_login()
{
    //当用户名为admin密码为12346则为登录成功
if( username->text()=="admin"&&password->text()=="123456")
{
    //登录成功
    login_success=new QLabel();
    //打开一个新的窗口
    login_success->show();
    //显示登录成功
    login_success->setText("登录成功");
    //设定标签的大小
    login_success->setFixedSize(200,50);
    //移动标签根据屏幕移动
    login_success->move(1135,550);
    //终端输出登录成功
    qDebug()<<"登录成功";
}else{
    //登录失败
    login_error=new QLabel();
   //打开一个新的窗口
    login_error->show();
    //显示登录失败
    login_error->setText("登录失败请重新输入用户名或密码");
    // 设定标签的大小
    login_error->setFixedSize(300,100);
      //移动标签根据屏幕移动
    login_error->move(1135,560);
    //清空用户名行编辑器
    username->clear();
    //清空密码行编译器
    password->clear();
}
 
}
=======================================================================================
 

  • 17
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值