当前位置: 首页 > news >正文

Qt消息对话框的实现

Widget.cpp

#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);this -> setWindowIcon(QIcon(":/picture/hp.jpg"));//设置窗口图标this -> setWindowFlag(Qt::FramelessWindowHint, 1);//无边框setAttribute(Qt::WA_TranslucentBackground);//窗口透明
//    this->setStyleSheet("border-radius:30px;");this->setAttribute(Qt::WA_TranslucentBackground);
}Widget::~Widget()
{delete ui;
}void Widget::on_pushButton_clicked()
{if(ui -> ac_line -> text() == "admin"){if(ui -> pa_line -> text() == "123456"){succes_login();}else if(ui -> pa_line -> text() == ""){QMessageBox msg(QMessageBox::Warning,//图标"错误",//标题"请输入密码",//文本QMessageBox::Yes | QMessageBox::No,//提供按钮this//指定父组件);
//            msg.setStyleSheet("background-color: white; border: 2px solid black; "
//                              "QMessageBox::ButtonBox { margin-top: 10px; }"
//                              "QMessageBox QPushButton { margin: 5px; }");msg.setStyleSheet("background-color: rgb(164, 164, 255);");msg.setWindowFlag(Qt::FramelessWindowHint, 1);msg.button(QMessageBox::Yes)->setStyleSheet("background-color: rgb(40, 40, 40);color:white");msg.button(QMessageBox::No)->setStyleSheet("background-color: white");//            this -> setWindowIcon(QIcon(":/picture/hp.jpg"));//设置窗口图标
//            this -> setWindowFlag(Qt::FramelessWindowHint, 1);//无边框
//            setAttribute(Qt::WA_TranslucentBackground);//窗口透明//(QMessageBox{background-color: white; border: 2px solid black; }
//            QMessageBox::ButtonBox { margin-top: 10px; }
//            QMessageBox QPushButton { margin: 5px; });int ret = msg.exec();//弹出对话框//根据用户的选择,执行不同的功能if(QMessageBox::No == ret){this -> close();}}else{
//            ui -> pa_line -> setText("");ui -> pa_line -> clear();QMessageBox msg(QMessageBox::Warning,//图标"错误",//标题"密码错误, 是否重新登录",//文本QMessageBox::Yes | QMessageBox::No,//提供按钮this//指定父组件);int ret = msg.exec();//弹出对话框//根据用户的选择,执行不同的功能if(ret == QMessageBox::No){this -> close();}}}else if(ui -> ac_line -> text() == ""){QMessageBox::information(this, "信息", "请填写账号密码", QMessageBox::Ok);ui -> pa_line -> setText("");}
}void Widget::succes_login()
{this -> close();emit my_jump();
}

chat.cpp

#include "chat.h"
#include "ui_chat.h"chat::chat(QWidget *parent) :QWidget(parent),ui(new Ui::chat)
{ui->setupUi(this);
}chat::~chat()
{delete ui;
}void chat::on_pushButton_9_clicked()
{//弹出第一个对话框 QFontDialogbool OK;QFont ft = QFontDialog::getFont(&OK, QFont("黑体", 14, 2), this);//判断用户if(OK){ui -> textEdit -> setCurrentFont(ft);}else{QMessageBox::information(this, "","未选择正确的字体");}
}void chat::jump_slot()
{this -> show();
}

main.cpp

#include "widget.h"
#include "chat.h"
#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();chat c;QObject::connect(&w, &Widget::my_jump, &c, &chat::jump_slot);return a.exec();
}


http://www.mrgr.cn/news/4566.html

相关文章:

  • icon文件解析和生成
  • 基于python的汽车数据分析与可视化---附源码99290
  • 干货实用帖 | PARASOFT与JENKINS 插件集成
  • 如何查找父体共享的评论到底是哪一个子体的——把评论拿走给新品用
  • 省市区三级联动数据+PHP接口
  • 字符串函数———C语言
  • 【教程】Ubuntu给pycharm添加侧边栏快捷方式
  • Appium定位元素
  • 【论文阅读】DaST: Data-free Substitute Training for Adversarial Attacks(2020)
  • 优思学院|如何在30分钟内评审一家供应商?SQE必需知道的11点
  • 【Docker系列】Docker 容器时区设置指南
  • 纯前端导出excel插件pikaz-excel-js使用小结
  • 小程序学习day09-WXS脚本、自定义组件-组件的创建、引用、组件与页面的区别、组件的样式隔离
  • linux下搭建MySQL8.0.25一主一从
  • 【Vitis开发】下载程序时Memory write error at 0x0,Cotex-A53 #0:EDITR not ready问题的解决
  • Android 架构模式之 MVC
  • Vue: v-html安全性问题
  • Go语言基础--嵌套循环(多重循环)
  • 论文翻译:Universal and Transferable Adversarial Attacks on Aligned Language Models
  • [数据集][目标检测]街灯路灯检测数据集VOC+YOLO格式1893张1类别