通过QT制作一个模仿微信主界面的界面(不要求实现具体通信功能)

main.cpp

cpp 复制代码
#include "widget.h"
#include "second.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    //实例化第二个界面
    Second s;
    QObject::connect(&w, &Widget::my_jump, &s, &Second::jump_slot);

    return a.exec();
}

second.cpp

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();
}

void Second::on_sendBtn_clicked()
{
    QString msg = ui->msgEdit->text();
    ui->msgWidget->addItem(msg);
}

widget.cpp

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    connect(ui->exit_btn, &QPushButton::clicked, this, &Widget::on_exit_btn_clicked);
    connect(ui->login_btn, &QPushButton::clicked, this, &Widget::on_login_btn_clicked);

}

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


void Widget::on_login_btn_clicked()
{
    if(ui->name_edit->text() == "admin" && ui->code_edit->text() == "123456"){
        QMessageBox::information(this,
                                 "提示",
                                 "登录成功",
                                 QMessageBox::Ok
                                 );
        this->close();
        emit my_jump();
    }else{
        QMessageBox msg(
                    QMessageBox::Warning,
                    "警告",
                    "账号和密码不匹配,是否重新登陆",
                    QMessageBox::Yes | QMessageBox::No,
                    this);
        int ret = msg.exec();
        if(ret == QMessageBox::Yes){  //判断警报
            this->show();
            ui->code_edit->clear();   //清除
        }else{
            this->close();   //关闭
        }
    }
}

void Widget::on_exit_btn_clicked()
{
    this->close();
}

second.ui

widget.ui

相关推荐
晨旭缘1 分钟前
后端日常启动及常用命令(Java)
java·开发语言
CodeAmaz1 分钟前
ArrayList 底层原理
java·arraylist
山峰哥2 分钟前
3000字深度解析:SQL调优如何让数据库查询效率提升10倍
java·服务器·数据库·sql·性能优化·编辑器
tkevinjd3 分钟前
JUC2(多线程中常用的成员方法)
java
天天摸鱼的java工程师8 分钟前
工作中 Java 程序员如何集成 AI?Spring AI、LangChain4j、JBoltAI 实战对比
java·后端
星辰_mya8 分钟前
RockerMQ之commitlog与consumequeue
java·开发语言
__万波__10 分钟前
二十三种设计模式(二十二)--策略模式
java·设计模式·策略模式
不想上班的小吕10 分钟前
采购申请创建(BAPI_PR_CREATE/BAPI_REQUISITION_CREATE)
java·服务器·数据库
专注VB编程开发20年13 分钟前
压栈顺序是反向(从右往左)的,但正因为是反向压栈,所以第一个参数反而离栈顶(ESP)最近。
java·开发语言·算法
椰汁菠萝14 分钟前
spring boot下使用gdal解析tif文件
java·native·gdal·0