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

qt-11基本对话框(消息框)

基本对话框--消息框

  • msgboxdlg.h
  • msgboxdlg.cpp
  • main.cpp
  • 运行图
    • QustionMsg
    • InFormationMsg
    • WarningMsg
    • CriticalMsg
    • AboutMsg
    • AboutAtMsg
    • 自定义

msgboxdlg.h

#ifndef MSGBOXDLG_H
#define MSGBOXDLG_H#include <QDialog>
#include <QLabel>
#include <QPushButton>
#include <QGridLayout>
#include <QMessageBox>class msgboxdlg : public QDialog
{Q_OBJECTpublic:msgboxdlg(QWidget *parent = nullptr);~msgboxdlg();
private slots:void ShowQustionMsg();void ShowInFormationMsg();void ShowWarningMsg();void ShowCriticalMsg();void ShowAboutMsg();void ShowAboutAtMsg();void ShowCustomMsg();
private:QLabel* Label;QPushButton* QuestionBtn;QPushButton* InformationBtn;QPushButton* WarningBtn;QPushButton* CriticalBtn;QPushButton* AboutBtn;QPushButton* AboutQtBtn;QPushButton* CustomBtn;QGridLayout* MainLayout;};
#endif // MSGBOXDLG_H

msgboxdlg.cpp

#include "msgboxdlg.h"msgboxdlg::msgboxdlg(QWidget *parent): QDialog(parent)
{setWindowTitle(tr("标准消息对话框实例"));//实例化控件对象Label = new QLabel(tr("请选择一种消息框"));QuestionBtn = new QPushButton(tr("QuestionMsg"));InformationBtn = new QPushButton(tr("InformationMsg"));WarningBtn = new QPushButton(tr("WarningMsg"));CriticalBtn = new QPushButton(tr("CriticalMsg"));AboutBtn = new QPushButton(tr("AboutMsg"));AboutQtBtn = new QPushButton(tr("AboutQtMsg"));CustomBtn = new QPushButton(tr("CustomMsg"));//布局MainLayout = new QGridLayout(this);MainLayout->addWidget(Label,0,0,1,2);MainLayout->addWidget(QuestionBtn,1,0);MainLayout->addWidget(InformationBtn,1,1);MainLayout->addWidget(WarningBtn,2,0);MainLayout->addWidget(CriticalBtn,2,1);MainLayout->addWidget(AboutBtn,3,0);MainLayout->addWidget(AboutQtBtn,3,1);MainLayout->addWidget(CustomBtn,4,0,1,2);//事件关联connect(QuestionBtn,SIGNAL(clicked()),this,SLOT(ShowQustionMsg()));connect(InformationBtn,SIGNAL(clicked()),this,SLOT(ShowInFormationMsg()));connect(WarningBtn,SIGNAL(clicked()),this,SLOT(ShowWarningMsg()));connect(CriticalBtn,SIGNAL(clicked()),this,SLOT(ShowCriticalMsg()));connect(AboutBtn,SIGNAL(clicked()),this,SLOT(ShowAboutMsg()));connect(AboutQtBtn,SIGNAL(clicked()),this,SLOT(ShowAboutAtMsg()));connect(CustomBtn,SIGNAL(clicked()),this,SLOT(ShowCustomMsg()));}msgboxdlg::~msgboxdlg() {}void msgboxdlg::ShowQustionMsg()
{Label->setText(tr("Question Message box"));switch(QMessageBox::question(this,tr("Question 消息框"),tr("您现在已经修改完成,是否要结束程序?"),QMessageBox::Ok|QMessageBox::Cancel,QMessageBox::Ok)){case QMessageBox::Ok:Label->setText(tr("Question button/ok"));break;case QMessageBox::Cancel:Label->setText(tr("Question button/cancel"));break;default:break;}return;
}void msgboxdlg::ShowInFormationMsg()
{Label->setText(tr("Information Message Box"));QMessageBox::information(this,tr("Information消息框"),tr("这是Information消息框测试,欢迎您!"));return;
}void msgboxdlg::ShowWarningMsg()
{Label->setText(tr("warning message box"));switch(QMessageBox::warning(this,tr("warning 消息框"),tr("您修改的文档内容还未保存,是否要保存文档"), QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel,QMessageBox::Save)){case QMessageBox::Save:Label->setText("Save");break;case QMessageBox::Discard:Label->setText("Discard");break;case QMessageBox::Cancel:Label->setText("Cancel");break;default:break;}return;}void msgboxdlg::ShowCriticalMsg()
{Label->setText(tr("Critical MessBox "));QMessageBox::critical(this,tr("Critical 消息框"),tr("这是一个critical 消息框"));return;
}void msgboxdlg::ShowAboutMsg()
{Label->setText(tr("about MessBox "));QMessageBox::about(this,tr("about 消息框"),tr("这是一个about 消息框"));return;
}void msgboxdlg::ShowAboutAtMsg()
{Label->setText(tr("aboutQt MessBox "));QMessageBox::aboutQt(this,tr("aboutQt 消息框"));return;
}void msgboxdlg::ShowCustomMsg()
{Label->setText(tr("Custom 消息框"));QMessageBox CustomBox;CustomBox.setWindowTitle(tr("自定义消息框"));QPushButton* YesBtn = CustomBox.addButton(tr("yes"),QMessageBox::ActionRole);QPushButton* NoBtn = CustomBox.addButton(tr("No"),QMessageBox::ActionRole);QPushButton* Cancel = CustomBox.addButton(QMessageBox::Cancel);CustomBox.setText(tr("这是一个用户自定义消息框"));CustomBox.setIconPixmap(QPixmap("312.png"));CustomBox.exec();if(CustomBox.clickedButton() == YesBtn){Label->setText(tr("Custom YesBtn消息"));return;}if(CustomBox.clickedButton() == NoBtn){Label->setText(tr("Custom NoBtn消息"));return;}if(CustomBox.clickedButton() == Cancel){Label->setText(tr("Custom Cancel消息"));return;}return;
}

main.cpp

#include "msgboxdlg.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);msgboxdlg w;w.show();return a.exec();
}

运行图

QustionMsg

在这里插入图片描述

InFormationMsg

在这里插入图片描述

WarningMsg

在这里插入图片描述

CriticalMsg

在这里插入图片描述

AboutMsg

在这里插入图片描述

AboutAtMsg

在这里插入图片描述

自定义

在这里插入图片描述

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【图形验证和AI智能及CHATGPT对抗影响的是用户体验】
  • 【大模型系列篇】Transformers综述--邱锡鹏
  • react的setState中为什么不能用++?
  • pygame开发课程系列(4): 游戏元素
  • 怎么直接在PDF上修改内容?随心编辑PDF内容
  • 日拱一卒(4)——leetcode学习记录:路径总和
  • python爬虫爬取某图书网页实例
  • Nginx禁用IP和IP段
  • 二叉树的判断
  • 详解 Redis 队列 实现
  • druid+logback打印sql执行日志
  • ubuntu 20 安装mysql workbench 过程
  • 图像--数据增强
  • 排序算法【归并排序】
  • XSS小游戏(题目+解析)DOM破坏!!!
  • Google 是如何开发 Web 框架的
  • 【RocksDB】TransactionDB源码分析
  • 0基础学习移动端适配
  • java 多线程基础, 我觉得还是有必要看看的
  • Js基础——数据类型之Null和Undefined
  • k个最大的数及变种小结
  • laravel with 查询列表限制条数
  • Python爬虫--- 1.3 BS4库的解析器
  • Quartz初级教程
  • SAP云平台运行环境Cloud Foundry和Neo的区别
  • TypeScript迭代器
  • Zepto.js源码学习之二
  • 第十八天-企业应用架构模式-基本模式
  • 订阅Forge Viewer所有的事件
  • 漫谈开发设计中的一些“原则”及“设计哲学”
  • 前端_面试
  • 如何打造100亿SDK累计覆盖量的大数据系统
  • 如何在 Tornado 中实现 Middleware
  • 译有关态射的一切
  • Play Store发现SimBad恶意软件,1.5亿Android用户成受害者 ...
  • 带你开发类似Pokemon Go的AR游戏
  • ​2021半年盘点,不想你错过的重磅新书
  • ​configparser --- 配置文件解析器​
  • ​LeetCode解法汇总518. 零钱兑换 II
  • ​如何使用QGIS制作三维建筑
  • #我与Java虚拟机的故事#连载08:书读百遍其义自见
  • (4)(4.6) Triducer
  • (a /b)*c的值
  • (BFS)hdoj2377-Bus Pass
  • (阿里云万网)-域名注册购买实名流程
  • (附源码)计算机毕业设计ssm本地美食推荐平台
  • (四)【Jmeter】 JMeter的界面布局与组件概述
  • (四)七种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (一)SpringBoot3---尚硅谷总结
  • (原创)Stanford Machine Learning (by Andrew NG) --- (week 9) Anomaly DetectionRecommender Systems...
  • (转载)从 Java 代码到 Java 堆
  • ./mysql.server: 没有那个文件或目录_Linux下安装MySQL出现“ls: /var/lib/mysql/*.pid: 没有那个文件或目录”...
  • .NET CLR基本术语
  • .NET Core 中的路径问题
  • .NET 设计模式初探