当前位置:   article > 正文

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

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

main.cpp

  1. #include "widget.h"
  2. #include "second.h"
  3. #include <QApplication>
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. Widget w;
  8. w.show();
  9. //实例化第二个界面
  10. Second s;
  11. QObject::connect(&w, &Widget::my_jump, &s, &Second::jump_slot);
  12. return a.exec();
  13. }

second.cpp

  1. #include "second.h"
  2. #include "ui_second.h"
  3. Second::Second(QWidget *parent) :
  4. QWidget(parent),
  5. ui(new Ui::Second)
  6. {
  7. ui->setupUi(this);
  8. }
  9. Second::~Second()
  10. {
  11. delete ui;
  12. }
  13. //第二个界面自定义的槽函数的实现
  14. void Second::jump_slot()
  15. {
  16. this->show();
  17. }
  18. void Second::on_sendBtn_clicked()
  19. {
  20. QString msg = ui->msgEdit->text();
  21. ui->msgWidget->addItem(msg);
  22. }

widget.cpp

  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. Widget::Widget(QWidget *parent)
  4. : QWidget(parent)
  5. , ui(new Ui::Widget)
  6. {
  7. ui->setupUi(this);
  8. ui->setupUi(this);
  9. this->setWindowFlag(Qt::FramelessWindowHint);
  10. this->setAttribute(Qt::WA_TranslucentBackground);
  11. connect(ui->exit_btn, &QPushButton::clicked, this, &Widget::on_exit_btn_clicked);
  12. connect(ui->login_btn, &QPushButton::clicked, this, &Widget::on_login_btn_clicked);
  13. }
  14. Widget::~Widget()
  15. {
  16. delete ui;
  17. }
  18. void Widget::on_login_btn_clicked()
  19. {
  20. if(ui->name_edit->text() == "admin" && ui->code_edit->text() == "123456"){
  21. QMessageBox::information(this,
  22. "提示",
  23. "登录成功",
  24. QMessageBox::Ok
  25. );
  26. this->close();
  27. emit my_jump();
  28. }else{
  29. QMessageBox msg(
  30. QMessageBox::Warning,
  31. "警告",
  32. "账号和密码不匹配,是否重新登陆",
  33. QMessageBox::Yes | QMessageBox::No,
  34. this);
  35. int ret = msg.exec();
  36. if(ret == QMessageBox::Yes){ //判断警报
  37. this->show();
  38. ui->code_edit->clear(); //清除
  39. }else{
  40. this->close(); //关闭
  41. }
  42. }
  43. }
  44. void Widget::on_exit_btn_clicked()
  45. {
  46. this->close();
  47. }

second.ui

widget.ui

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/83103
推荐阅读
相关标签
  

闽ICP备14008679号