message box
QMessageBox 弹出框上的按钮设置为中文
Qt 默认的弹出框上的按钮式英文,虽然也知道是什么意思,但终究不如中文看着顺眼。
QMessageBox box(QMessageBox::Warning,"标题","弹出框按钮更改为中文!");
box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
box.exec ();
弹出效果:

在网上查了很多资料,有各种各样的方法,弄得我晕头转向,毕竟我接触Qt才不过一个月。不过在我坚持不懈的努力下,总算是找到了一个便捷的方法。
QMessageBox box(QMessageBox::Warning,"标题","弹出框按钮更改为中文!");
box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
box.setButtonText (QMessageBox::Ok,QString("确 定"));
box.setButtonText (QMessageBox::Cancel,QString("取 消"));
box.exec ();
弹出效果:

怎么样,简单吧?
另外再附赠一个简单的弹出框类。虽然还没有办法返回用户点击的按钮,不过已经可以基本做到类似C#的使用效果了。这是我闲的无聊花了整整半天才搞定的。大概高手觉得很无趣吧?不过对我这种初学者来说,能弄到这种程度已经足以让我满足了。
这个类暂时先这样,等以后有机会再做补充。大概……
文件头:
#ifndef MESSAGEBOX_H
#define MESSAGEBOX_H
#include <QMessageBox>
#include <QPushButton>
#include <QString>
#include <QMap>
enum MessageBoxButtons
{
OK = 0, //消息框包含“确定”按钮
OKCancel = 1, //消息框包含“确定”和“取消”按钮
AbortRetryIgnore = 2, //消息框包含“中止”、“重试”和“忽略”按钮
YesNoCancel = 3, //消息框包含“是”、“否”和“取消”按钮
YesNo = 4, //消息框包含“是”和“否”按钮
RetryCancel = 5 //消息框包含“重试”和“取消”按钮
};
enum MessageBoxIcon
{
None = 0, //消息框未包含符号
Hand = 1, //该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的
Question = 2, //该消息框包含一个符号,该符号是由一个圆圈和其中的一个问号组成的
Exclamation = 3, //该消息框包含一个符号,该符号是由一个黄色背景的三角形及其中的一个感叹号组成的
Asterisk = 4, //该消息框包含一个符号,该符号是由一个圆圈及其中的小写字母 i 组成的
Stop = 5, //该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的
Error = 6, //该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的
Warning = 7, //该消息框包含一个符号,该符号是由一个黄色背景的三角形及其中的一个感叹号组成的
Information = 8 //该消息框包含一个符号,该符号是由一个圆圈及其中的小写字母 i 组成的
};
class MessageBox
{
public:
static void Show(const QString & content);
static void Show(const QString & content, const QString & caption);
static void Show(const QString & content, const QString & caption, MessageBoxButtons button);
static void Show(const QString & content, const QString & caption, MessageBoxButtons button, MessageBoxIcon icon);
private:
static QMap<QString,QMessageBox::StandardButton> GetButton(MessageBoxButtons type);
static QString GetButtonText(QMessageBox::StandardButton standar);
signals:
};
#endif // MESSAGEBOX_H
#include "MessageBox.h"
QString MessageBox::GetButtonText (QMessageBox::StandardButton standar)
{
switch (standar)
{
case QMessageBox::Ok:
return QString("确 定");
case QMessageBox::Cancel:
return QString("取 消");
case QMessageBox::Abort:
return QString("终 止");
case QMessageBox::Retry:
return QString("重 试");
case QMessageBox::Ignore:
return QString("忽 略");
case QMessageBox::Yes:
return QString("是");
case QMessageBox::No:
return QString("否");
default:
return QString("OK");
}
}
QMap<QString,QMessageBox::StandardButton> MessageBox:: GetButton(MessageBoxButtons type)
{
QMap<QString,QMessageBox::StandardButton> map;
switch (type)
{
case MessageBoxButtons(0):
default:
map.insert (GetButtonText(QMessageBox::Ok),QMessageBox::Ok);
break;
case MessageBoxButtons(1):
map.insert (GetButtonText(QMessageBox::Ok),QMessageBox::Ok);
map.insert (GetButtonText(QMessageBox::Cancel),QMessageBox::Cancel);
break;
case MessageBoxButtons(2):
map.insert (GetButtonText(QMessageBox::Abort),QMessageBox::Abort);
map.insert (GetButtonText(QMessageBox::Retry),QMessageBox::Retry);
map.insert (GetButtonText(QMessageBox::Ignore),QMessageBox::Ignore);
break;
case MessageBoxButtons(3):
map.insert (GetButtonText(QMessageBox::Yes),QMessageBox::Yes);
map.insert (GetButtonText(QMessageBox::No),QMessageBox::No);
map.insert (GetButtonText(QMessageBox::Cancel),QMessageBox::Cancel);
break;
case MessageBoxButtons(4):
map.insert (GetButtonText(QMessageBox::Yes),QMessageBox::Yes);
map.insert (GetButtonText(QMessageBox::No),QMessageBox::No);
break;
case MessageBoxButtons(5):
map.insert (GetButtonText(QMessageBox::Retry),QMessageBox::Retry);
map.insert (GetButtonText(QMessageBox::Cancel),QMessageBox::Cancel);
break;
}
return map;
}
void MessageBox:: Show(const QString & content, const QString & caption, MessageBoxButtons button,
MessageBoxIcon icon)
{
QMessageBox::Icon con;
switch(icon)
{
case MessageBoxIcon(0):
con = QMessageBox::NoIcon;
break;
case MessageBoxIcon(1):
case MessageBoxIcon(5):
case MessageBoxIcon(6):
con = QMessageBox::Critical;
break;
case MessageBoxIcon(2):
con = QMessageBox::Question;
break;
case MessageBoxIcon(3):
case MessageBoxIcon(7):
con = QMessageBox::Warning;
break;
default:
con = QMessageBox::Information;
break;
}
QMap<QString,QMessageBox::StandardButton> ms = GetButton(button);
QMessageBox box(con, caption, content);
int size = ms.size ();
switch(size)
{
case 1:
box.setStandardButtons (ms.first ());
box.setButtonText (ms.values().at (0),ms.keys ().at (0));
break;
case 2:
box.setStandardButtons (ms.first () | ms.last ());
box.setButtonText (ms.values().at (0),ms.keys ().at (0));
box.setButtonText (ms.values().at (1),ms.keys ().at (1));
break;
case 3:
box.setStandardButtons (ms.values ().at (0)|ms.values ().at (1)|ms.values ().at (2));
box.setButtonText (ms.values().at (0),ms.keys ().at (0));
box.setButtonText (ms.values().at (1),ms.keys ().at (1));
box.setButtonText (ms.values().at (2),ms.keys ().at (2));
break;
}
box.exec ();
}
void MessageBox:: Show(const QString & content, const QString & caption, MessageBoxButtons button)
{
Show(content,caption,button,MessageBoxIcon(0));
}
void MessageBox:: Show(const QString & content, const QString & caption)
{
Show(content,caption,MessageBoxButtons(0));
}
void MessageBox:: Show(const QString & content)
{
Show(content," ");
}
message box的更多相关文章
- Wix: Show conditional message box
For example: Scenario: Show message box only during installation and MYPROPERTY has to be equal to & ...
- a message box to confirm the action
当点击窗口的X按钮时,弹出确认退出消息框,继续点击Yes,退出.否则,窗口继续处于打开状态 代码: """ This program shows a confirmati ...
- Message Box Position
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- mint-ui message box 问题;
当引用 mint-ui message box 的 出现的问题,我暂时是不知道为什么: 官网是这样写的: 于是 我也这么做的:(这里用小写,具体我也不清楚,毕竟文档上写的也不是很清楚,但是只有这样写, ...
- Qt学习笔记-制作一个计算器-对话框Message Box
在做计算器的前提先做一个加法器. 设计界面. 在点击计算的时候,获取前两个输入框中的数据相加后显示在第三个输入框. toInt是将字符串转换为数字.number静态函数是将数字转化为字符串. 加法器已 ...
- vue 结合mint-ui Message box的使用方法
两种方式使用: 一.全局注册 1.在main.js中引入 //引入 import { MessageBox } from 'mint-ui'; //全局使用,挂载到原型上 Vue.prototyp ...
- Win32 error code message
http://fit.c2.com/fit/files/LispPlatform/lisp/clisp-2.28/src/errwin32.d # Calls a function, passing ...
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- 2000条你应知的WPF小姿势 基础篇<15-21>
在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师,对C#和WPF有着极深的热情.最为出色的是他维护了两个博客:2,000Things You Should Know ...
随机推荐
- HTTP的简单的解析
HTTP 中文全称为超文本传输协议是一种为分布式,合作式,多媒体信息系统服务,面向应用层的协议.它是一种通用的,不分状态(stateless)的协议,除了诸如名称服务和分布对象管理系统之类的超文本用途 ...
- Oracle错误——user ** lacks CREATE SESSION privilege logon denied
错误 在删除一个用户TEST的情况下,再次新建用户TEST并赋予sysdba权限,使用plsqldev工具登录数据库TEST用户,报错user TEST lacks CREATE SESSION p ...
- AJAX理解
注:首先我们要明白请求是什么?请求分两种,一.静态请求(如:返回js.css.图片等) 二.动态请求(返回跟用户有关的数据) http(apache.nginx等)服务器会判断如果是一个静态请求,会直 ...
- spring boot +mybatis 整合 连接数据库测试(从0到1)
spring boot 整合mybatis 1.打开idea创建一个项目 2.在弹出的窗口中选择spring initializr(初始化项目),点击next 3.接下来填写group 与artifa ...
- Learning-Python【20】:Python常用模块(3)—— shelve、pickle、json、xml、configparser
什么是序列化/反序列化? 序列化就是将内存中的数据结构转换成一种中间格式存储到硬盘或者基于网络传输,反序列化就是硬盘中或者网络中传来的一种数据格式转换成内存中数据结构 为什么要有序列化/反序列化? 1 ...
- Linux系统初始配置标准化
Inux系统标准化 配置环境:4台Centos7.6版本的虚拟机,刚刚最小化安装完成,未作任何操作,分别是node1.node2.node3.node4 本文打算利用ansible工具对这四台虚拟机进 ...
- MySQL中case then用法
1.查询图书价格,若价格为null,则显示unknown,若价格为10到20, 则显示10 to 20 SELECT price, CASE WHEN price='null' THEN 'UnKno ...
- 综述 - 染色质可及性与调控表观基因组 | Chromatin accessibility and the regulatory epigenome
RNA-seq这个工具该什么时候用?ATAC-seq该什么时候用?有相当一部分项目设计不行,导致花大钱测了一些没有意义的数据. 还是在中心法则这个框架下来解释,这是生物信息的核心.打开华大科技服务官网 ...
- gulp下单页面应用打包
项目地址:https://pan.baidu.com/s/1cu4WW2 之前已经说过多入口打包,最近正好做一个单页面应用,之前多人口是用webpack打包的,但是感觉webpack比较重,单页面我又 ...
- 机器学习 之梯度提升树GBDT
目录 1.基本知识点简介 2.梯度提升树GBDT算法 2.1 思路和原理 2.2 梯度代替残差建立CART回归树 1.基本知识点简介 在集成学习的Boosting提升算法中,有两大家族:第一是AdaB ...