Qt(10.8)

作业:完善登录界面

源文件

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"
#include<QDebug>
#include<QLabel>
#include<QMessageBox>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
   ui->setupUi(this);
   this->setWindowTitle("登录界面");
   this->setWindowIcon(QIcon("D:\\wjl\\C++\\Qt\\day01\\01d\\pictrue\\qq")); //设置窗口图标
   ui->btn1->setIcon(QIcon("D:\\wjl\\C++\\Qt\\day01\\01d\\pictrue\\login"));//设置图标
   ui->btn1->setEnabled(true);//设置自适应

   ui->btn2->setIcon(QIcon("D:\\wjl\\C++\\Qt\\day01\\01d\\pictrue\\cancel"));//设置图标
   ui->btn2->setEnabled(true);//设置自适应

    ui->lineEdit_2->setPlaceholderText("QQ号/手机号/邮箱");
    ui->lineEdit->setPlaceholderText("输入密码");
    ui->lineEdit->setEchoMode(QLineEdit::Password);        //设置回显模式

    ui->label->setPixmap(QPixmap("D:\\wjl\\C++\\Qt\\day01\\01d\\pictrue\\logo"));
    ui->label->setScaledContents(true);

    ui->label_3->setPixmap(QPixmap("D:\\wjl\\C++\\Qt\\day01\\01d\\pictrue\\userName"));
    ui->label_3->setScaledContents(true);

    ui->label_2->setPixmap(QPixmap("D:\\wjl\\C++\\Qt\\day01\\01d\\pictrue\\passwd"));
    ui->label_2->setScaledContents(true);


}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_btn1_clicked()
{
    if(ui->lineEdit->text()==ui->lineEdit_2->text())
    {
        QMessageBox box(QMessageBox::Information,              //图标,信息图标
                           "信息",                             //对话框标题
                           "登录成功",                        //对话框文本内容
                           QMessageBox::Ok,   //对话框提供的按钮
                           this);                              //父组件
           //3、显示对话框:并返回用户点击的那个按钮值
           int btn = box.exec();
           //4、判断用户点击的按钮值
           if(btn == QMessageBox::Ok)
           {
               box.close();
           }
    this->close();
    emit jump();
        qDebug()<<"登录成功";
    }
    else
    {
            //调用静态成员函数来完成对话框
            int btn = QMessageBox::warning(this,
                                 "警告",                       //对话框标题
                                 "账号和密码不匹配,是否重新登录",              //对话框文本
                                 QMessageBox::Yes|QMessageBox::No, //提供的按钮
                                 QMessageBox::Yes);              //默认按钮

            //2、对用户点击的按钮进行判断
            if(btn == QMessageBox::Yes)
            {
                ui->lineEdit->clear();
            }
            else if(btn==QMessageBox::No)
            {
                this->close();
            }

    }
}

void Widget::on_btn2_clicked()
{
    QMessageBox box(QMessageBox::Question,              //图标,问题图标
                       "问题",                             //对话框标题
                       "是否退出登录?",                        //对话框文本内容
                       QMessageBox::Yes|QMessageBox::No,   //对话框提供的按钮
                       this);
       //3、显示对话框:并返回用户点击的那个按钮值
       int btn = box.exec();
       if(btn == QMessageBox::Yes)
       {
          this->close();
       }else if(btn == QMessageBox::No)
       {
          box.close();
       }
}
相关推荐
一只脑洞君19 分钟前
Kubernetes(K8s)的简介
java·容器·kubernetes
zygswo20 分钟前
程序猿成长之路之设计模式篇——设计模式简介
java·设计模式
除了代码啥也不会1 小时前
springboot项目发送邮件
java·spring boot·spring
无敌の星仔2 小时前
一个月学会Java 第7天 字符串与键盘输入
java·开发语言·python
GGBondlctrl2 小时前
【JavaEE初阶】多线程案列之定时器的使用和内部原码模拟
java·开发语言·定时器·timer的使用·定时器代码模拟
多多*2 小时前
OJ在线评测系统 微服务高级 Gateway网关接口路由和聚合文档 引入knife4j库集中查看管理并且调试网关项目
java·运维·微服务·云原生·容器·架构·gateway
惜.己3 小时前
java中日期时间类的api
java·开发语言·intellij-idea·idea·intellij idea
Bartender_Jill3 小时前
[ROS2]解决PyQt5和sip的各种报错问题 stderr: qt_gui_cpp
开发语言·python·qt·机器人·数据可视化
橘子海全栈攻城狮4 小时前
【源码+文档+调试讲解】基于Android的固定资产借用管理平台
android·java·spring boot·后端·python·美食