通过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

相关推荐
知其然亦知其所以然9 分钟前
JVM社招面试题:队列和栈是什么?有什么区别?我在面试现场讲了个故事…
java·后端·面试
harmful_sheep17 分钟前
Spring 为何需要三级缓存解决循环依赖,而不是二级缓存
java·spring·缓存
星辰大海的精灵18 分钟前
如何确保全球数据管道中的跨时区数据完整性和一致性
java·后端·架构
大大。21 分钟前
van-tabbar-item选中active数据变了,图标没变
java·服务器·前端
nc_kai24 分钟前
Flutter 之 每日翻译 PreferredSizeWidget
java·前端·flutter
Codebee34 分钟前
OneCode:AI时代的先锋——注解驱动技术引领开发范式变革
java
勤奋的知更鸟34 分钟前
Java 编程之状态模式
java·开发语言·状态模式
清醒的兰42 分钟前
Qt 基于TCP套接字编程
网络·qt·tcp
架构个驾驾1 小时前
深入浅出MyBatis-Plus实战指南
java
SimonKing1 小时前
解锁万能文件内容分析工具:Apache Tika
java·后端·程序员