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();
       }
}
相关推荐
asom222 分钟前
MVC vs DDD
java·mvc·ddd
凯子坚持 c4 分钟前
基于C++构建DeepSeek大模型推理SDK:从架构设计到工程落地
java·数据库·c++
星河耀银海6 分钟前
C++ 异常处理机制:异常捕获、自定义异常与实战应用
android·java·c++
载数而行5206 分钟前
Qt中的信号和槽
qt
longzhen9z15 分钟前
SpringSecurity踢出指定用户
java
洛阳泰山22 分钟前
开源智能体搭建平台MaxKB4j 技术文档
java·开源·llm·springboot·agent·rag·langchain4j
我命由我1234527 分钟前
Android 开发 - UriMatcher(一个 URI 分类器)
android·java·java-ee·kotlin·android studio·android-studio·android runtime
sinat_2554878127 分钟前
为 System.out 编写我们自己的包装类
java·开发语言·算法
a8a30228 分钟前
Springboot中CommandLineRunner的用法以及执行顺序的控制
java·spring boot·spring
寒鸦飞尽32 分钟前
QT中自定义标题栏
qt