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. python 源码解读2

    http://www.jianshu.com/users/4d4a2f26740b/latest_articles http://blog.csdn.net/ssjhust123/article/ca ...

  2. SQL SERVER NULL值和连接注意问题

    联接表的列中的 null 值(如果有)互相不匹配.如果其中一个联接表的列中出现空值,只能通过外部联接返回这些空值(除非 WHERE 子句不包括空值).   下面的两个表中,每个表中要参与联接的列中均包 ...

  3. 小白日记27:kali渗透测试之Web渗透-Http协议基础,WEB

    Http协议基础 Web技术发展[http://www.cnblogs.com/ProgrammerGE/articles/1824657.html] 静态WEB[网页] 动态WEB 属于一种应用程序 ...

  4. DataBase 之 表操作

    1:向表中添加字段 Alter table [表名] add [列名] 类型 2: 删除字段 Alter table [表名] drop column [列名] 3: 修改表中字段类型 (可以修改列的 ...

  5. Android(java)学习笔记79:java中InetAddress类概述和使用

    要想让网络中的计算机能够互相通信,必须为每台计算机指定一个标识号,通过这个标识号来指定要接受数据的计算机和识别发送的计算机. 在TCP/IP协议中,这个标识号就是IP地址. 那么,我们如果获取和操作I ...

  6. some words we should know

    2010年,芬兰艺术家Mikko Kuorinki做了一件独特的艺术品. 他在赫尔辛基的奇亚斯玛当代艺术博物馆(Kiasma museum),找了一堵墙,装了一个175 x 320cm的木架子,上面用 ...

  7. 【VMware虚拟化解决方案】设计和配置VMware vCenter 5.5

    在这之前,我们已经对VMware ESXi 5.5进行了整个环境的设计和规划,虽然安装VMware ESXi 5.5在CPU的选型.网络的设计.共享存储的方式.虚拟化资源的需求和安装ESXI的模式等一 ...

  8. 【极角排序、扫描线】UVa 1606 - Amphiphilic Carbon Molecules(两亲性分子)

    Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new class of ...

  9. android图片压缩方法

    android 图片压缩方法: 第一:质量压缩法: private Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = ...

  10. 取消Win7任务栏窗口自动排序

    点击“开始”菜单,在“搜索程序和文件”框中输入“关闭自动窗口排列”,找到后打开,找到“防止将窗口移动到屏幕边缘时自动排列窗口”这一项,勾上后点击确定就可以了.