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 = , //消息框包含“确定”按钮
OKCancel = , //消息框包含“确定”和“取消”按钮
AbortRetryIgnore = , //消息框包含“中止”、“重试”和“忽略”按钮
YesNoCancel = , //消息框包含“是”、“否”和“取消”按钮
YesNo = , //消息框包含“是”和“否”按钮
RetryCancel = //消息框包含“重试”和“取消”按钮
}; enum MessageBoxIcon
{
None = , //消息框未包含符号
Hand = , //该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的
Question = , //该消息框包含一个符号,该符号是由一个圆圈和其中的一个问号组成的
Exclamation = , //该消息框包含一个符号,该符号是由一个黄色背景的三角形及其中的一个感叹号组成的
Asterisk = , //该消息框包含一个符号,该符号是由一个圆圈及其中的小写字母 i 组成的
Stop = , //该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的
Error = , //该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的
Warning = , //该消息框包含一个符号,该符号是由一个黄色背景的三角形及其中的一个感叹号组成的
Information = //该消息框包含一个符号,该符号是由一个圆圈及其中的小写字母 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():
default:
map.insert (GetButtonText(QMessageBox::Ok),QMessageBox::Ok);
break;
case MessageBoxButtons():
map.insert (GetButtonText(QMessageBox::Ok),QMessageBox::Ok);
map.insert (GetButtonText(QMessageBox::Cancel),QMessageBox::Cancel);
break;
case MessageBoxButtons():
map.insert (GetButtonText(QMessageBox::Abort),QMessageBox::Abort);
map.insert (GetButtonText(QMessageBox::Retry),QMessageBox::Retry);
map.insert (GetButtonText(QMessageBox::Ignore),QMessageBox::Ignore);
break;
case MessageBoxButtons():
map.insert (GetButtonText(QMessageBox::Yes),QMessageBox::Yes);
map.insert (GetButtonText(QMessageBox::No),QMessageBox::No);
map.insert (GetButtonText(QMessageBox::Cancel),QMessageBox::Cancel);
break;
case MessageBoxButtons():
map.insert (GetButtonText(QMessageBox::Yes),QMessageBox::Yes);
map.insert (GetButtonText(QMessageBox::No),QMessageBox::No);
break;
case MessageBoxButtons():
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():
con = QMessageBox::NoIcon;
break;
case MessageBoxIcon():
case MessageBoxIcon():
case MessageBoxIcon():
con = QMessageBox::Critical;
break;
case MessageBoxIcon():
con = QMessageBox::Question;
break;
case MessageBoxIcon():
case MessageBoxIcon():
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 :
box.setStandardButtons (ms.first ());
box.setButtonText (ms.values().at (),ms.keys ().at ());
break;
case :
box.setStandardButtons (ms.first () | ms.last ());
box.setButtonText (ms.values().at (),ms.keys ().at ());
box.setButtonText (ms.values().at (),ms.keys ().at ());
break;
case :
box.setStandardButtons (ms.values ().at ()|ms.values ().at ()|ms.values ().at ());
box.setButtonText (ms.values().at (),ms.keys ().at ());
box.setButtonText (ms.values().at (),ms.keys ().at ());
box.setButtonText (ms.values().at (),ms.keys ().at ());
break;
}
box.exec ();
} void MessageBox:: Show(const QString & content, const QString & caption, MessageBoxButtons button)
{
Show(content,caption,button,MessageBoxIcon());
} void MessageBox:: Show(const QString & content, const QString & caption)
{
Show(content,caption,MessageBoxButtons());
} void MessageBox:: Show(const QString & content)
{
Show(content," ");
}

QMessageBox 弹出框上的按钮设置为中文的更多相关文章

  1. jeecg 弹出框 点击按钮回调父页面 返回值

    jeecg 弹出框 点击按钮回调父页面 返回值 <t:base type="jquery"></t:base> <t:base type=" ...

  2. [js]uploadify结合jqueryUI弹出框上传,js中的冒出的bug,又被ie坑了

    引言 最近在一个项目中,在用户列表中需要对给没有签名样本的个别用户上传签名的样本,就想到博客园中上传图片使用弹出框方式,博客园具体怎么实现的不知道,只是如果自己来弄,想到两个插件的结合使用,在弹出框中 ...

  3. bootstrap 弹出框点击其他区域时弹出框不消失选项设置

    默认情况下,bootstrap 弹出框点击其他区域时,弹出框会自动关闭,在很多时候,我们可能会希望达到和原生弹出框一样的效果,避免不小心点击其他区域时弹框自动隐藏,尤其是对于一些复杂的表单,重复填写可 ...

  4. 【PyQt5-Qt Designer】QMessageBox 弹出框总结

    QMessageBox QMessageBox类中常用方法 方法  描述 information(QWdiget parent,title,text,buttons,defaultButton) 弹出 ...

  5. 让UIWebView弹出键盘上的按钮显示中文

    UIWebView是一个很常用的视图,一般用来加载网页,比如百度: 点击文本框输入框后,会弹出一个带有toolbar的键盘,toolbar中有3个辅助按钮 有了这3个按钮,是方便很多,但默认是英文的, ...

  6. 解决IE6下select显示在弹出框上问题

    利用定位position:absolute;z-index:1;和iframe[z-index:-1]来解决此问题,最好根据需要加上: border='0' frameborder='0' scrol ...

  7. input file上传文件弹出框的默认格式设置

    我们使用html的input 标签type="flie"时,如何设置默认可选的文件格式 <input id="doc_file" type="f ...

  8. firefox下载文件弹出框之终极解决方案-vbs模拟键盘操作

    由于近期一直被firefox的保存文件弹出框困扰,摸索尝试过几种方法,已有的方法可以跑通但是对对效果不太满意,因此一直在寻找合适的解决办法. 最近发现了也可以通过VBS来处理弹出框,速度也不错,其原理 ...

  9. Android 学习笔记之AndBase框架学习(二) 使用封装好的进度框,Toast框,弹出框,确认框...

    PS:渐渐明白,在实验室呆三年都不如在企业呆一年... 学习内容: 1.使用AbActivity内部封装的方法实现进度框,Toast框,弹出框,确认框...   AndBase中AbActivity封 ...

随机推荐

  1. 【ZZ】Python入门神图

    http://mp.weixin.qq.com/s?__biz=MzA3OTIxNTA0MA==&mid=401383338&idx=1&sn=73009cce06d58656 ...

  2. 最简单的Java调用C/C++代码的步骤

    1)首先在Java类中声明一个native的方法 (2)使用javah命令生成包含native方法声明的C/C++头文件 (3)按照生成的C/C++头文件来写C/C++源文件 (4)将C/C++源文件 ...

  3. 最小K个数之和

    描述 输入n个整数,输出其中最小的K个数之和.例如输入4,5,1,1,6,2,7,3,3这9个数字,当k=4,则输出最小的4个数之和为7(1,1,2,3). 输入 测试样例组数不超过10 每个测试案例 ...

  4. 一个不错的java的配置文件的设置

    package property; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStre ...

  5. 如何删除C/C++源代码中的注释

    具体代码: #include <stdlib.h>  #include <stdio.h>  //删除注释  void commentFilter(FILE* sourceFi ...

  6. [转]DataTable用中使用Compute 实现简单的DataTable数据的统计

    本文转自:http://blog.csdn.net/zwxrain/article/details/252285 調用格式: object DataTable.Compute(string expre ...

  7. LeetCode 258

    Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only ...

  8. 24小时学通Linux内核--内核探索工具类

    寒假闲下来了,可以尽情的做自己喜欢的事情,专心待在实验室里燥起来了,因为大二的时候接触过Linux,只是关于内核方面确实是不好懂,所以十天的时间里还是希望能够补充一下Linux内核相关知识,接下来继续 ...

  9. HTML+CSS3 纯代码实现转盘效果

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  10. Android开发—— Native 与 Web 之架构抉择

    前 言 移动App是对URL和搜索引擎的革命,当今移动App开发貌似出现两大阵营:Native 和 Web,各自都认为自己才是未来的趋势,Native操作流畅.迅速,Web开发周期相对较短,还能轻松跨 ...