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. Seconds_Behind_Master

    http://blog.chinaunix.net/uid-28212952-id-3494560.html 今天同事遇到一个故障,xtrabackup备份中flush tables with rea ...

  2. 非托管C++通过C++/CLI包装调用C# DLL

    项目中要给其它客户程序提供DLL做为接口,该项目是在.Net4.0平台下开发.终所周知.Net的各个版本之间存在着兼容性的问题,但是为了使用高版本运行平台的新特性,又不得不兼顾其它低版本平台客户程序的 ...

  3. 如何手动添加Android Dependencies包

    在ADT16 之前可以在工程里面做关联,eclipse会在工程上自动添加ReferenceLibrary.新版本的ADT修改了第三方jar的导入方式,只需要在工程目录下新建libs文件夹,注意是lib ...

  4. X-Sequence

    Description Let {xi} be the infinite sequence of integers: 1) x0 = A; 2) xi = (alpha * xi-1^2 + beta ...

  5. 用RSA实现Web单点登录密码的加密传输

    在使用通用权限管理系统(吉日嘎拉)的单点登录功能时,对登录密码使用了RSA加密(非对称加密),有使用这个权限管理系统的可参考下. 前端部分,请引用以下几个js文件: <script type=& ...

  6. Debian 7 安装 Docker

    Debian 7更新内核到3.16后 一.添加docker源 在source.list中加入: # Docker Repo deb https://get.docker.io/ubuntu docke ...

  7. Windows Azure 微软公有云体验(二) 存储成本比较分析

    Windows Azure 微软公有云已经登陆中国有一段时间了,现在是处于试用阶段,Windows Azure的使用将会给管理信息系统的开发.运行.维护带来什么样的新体验呢? Windows Azur ...

  8. [改善Java代码]建议40:匿名类的构造函数很特殊

    建议40: 匿名类的构造函数很特殊 在上一个建议中我们讲到匿名类虽然没有名字,但可以有一个初始化块来充当构造函数,那这个构造函数是否就和普通的构造函数完全一样呢?我们来看一个例子,设计一个计算器,进行 ...

  9. [需再总结]SSH整合代码生成器

    package cn.itcast.invoice.util.generator; import java.io.BufferedWriter; import java.io.File; import ...

  10. iOS下编译ffmpeg

    网络上搜索“ios ffmpeg 编译”,文章一大把,但我编译还是费了很大的功夫才编译成功.很多文章只是把步骤列了出来,但是每个人的系统环境,或者程序版本都不一样,结果出现各种的错误.我把自己编译过程 ...