通过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、PHP、ASP、JSP、Kotlin、.NET、Go
java·kotlin·go·php·.net·jsp·asp
罗曼蒂克在消亡4 分钟前
2.3MyBatis——插件机制
java·mybatis·源码学习
Fairy_sevenseven9 分钟前
【二十八】【QT开发应用】模拟WPS Tab
开发语言·qt·wps
_GR16 分钟前
每日OJ题_牛客_牛牛冲钻五_模拟_C++_Java
java·数据结构·c++·算法·动态规划
无限大.29 分钟前
c语言200例 067
java·c语言·开发语言
余炜yw31 分钟前
【Java序列化器】Java 中常用序列化器的探索与实践
java·开发语言
攸攸太上31 分钟前
JMeter学习
java·后端·学习·jmeter·微服务
Kenny.志34 分钟前
2、Spring Boot 3.x 集成 Feign
java·spring boot·后端
Death20035 分钟前
Qt 中的 QListWidget、QTreeWidget 和 QTableWidget:简化的数据展示控件
c语言·开发语言·c++·qt·c#
不修×蝙蝠36 分钟前
八大排序--01冒泡排序
java