• 14225阅读
  • 8回复

[提问]QMessagebox中按钮中文问题 [复制链接]

上一主题 下一主题
离线cityfantom
 

只看楼主 倒序阅读 楼主  发表于: 2009-06-17
— 本帖被 XChinux 从 Qt基础编程 移动到本区(2013-04-01) —
在程序中用QMessageBox中的静态方法弹出个提示框,但其按钮还是“OK”“Cancel”,能不能改为中文,如“确定”“取消”
离线vc_2003
只看该作者 1楼 发表于: 2009-06-18
QMessageBox::warning(this,tr("test"), tr("msg"), tr("Yes"), tr("No"), tr("Cancel"));

然后翻译tr("Yes"), tr("No"), tr("Cancel")三个即可
离线shiroki

只看该作者 2楼 发表于: 2009-06-18
要把qt的翻译文件也载入进来, button就会翻译了。
--
shiro is White
ki is tree
http://www.cuteqt.com
论坛 http://www.cuteqt.com/bbs
博客 http://www.cuteqt.com/blog
博客镜像: http://sites.cuteqt.com/cuteqt
Linux/Qt/嵌入式讨论群 http://qun.qq.com/air/5699823
离线vc_2003
只看该作者 3楼 发表于: 2009-06-18
int warning ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2 = 0 )这种是没法翻译的;

int warning ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )这种是可以翻译的,只要翻译 button0Text 就可以。
离线vc_2003
只看该作者 4楼 发表于: 2009-06-18
仔细看下面解释:

int QMessageBox::warning ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 ) [static]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Displays a warning message box with a caption, a text, and 1, 2 or 3 buttons. Returns the number of the button that was clicked (0, 1, or 2).
button0Text is the text of the first button, and is optional. If button0Text is not supplied, "OK" (translated) will be used. button1Text is the text of the second button, and is optional, and button2Text is the text of the third button, and is optional. defaultButtonNumber (0, 1 or 2) is the index of the default button; pressing Return or Enter is the same as clicking the default button. It defaults to 0 (the first button). escapeButtonNumber is the index of the Escape button; pressing Escape is the same as clicking this button. It defaults to -1; supply 0, 1, or 2 to make pressing Escape equivalent to clicking the relevant button.
If parent is 0, the message box becomes an application-global modal dialog box. If parent is a widget, the message box becomes modal relative to parent.
Note: If you do not specify an Escape button then if the Escape button is pressed then -1 will be returned. It is suggested that you specify an Escape button to prevent this from happening.
离线cityfantom

只看该作者 5楼 发表于: 2009-06-19
多谢大家,还是总版主的方式好,只要Copy一下qt_zh_CN.qm文件就可以了,这样写程序也方便,不用自已以后翻译.
离线wisconxing
只看该作者 6楼 发表于: 2009-07-01
请问cityfantom是如何操作的,能给个具体的说法吗? 我也被此问题困扰。谢谢
离线mqguodong
只看该作者 7楼 发表于: 2010-07-22
回 6楼(wisconxing) 的帖子
在代码中加入
QTranslator translator(0);
translator.load("qt_zh_CN.qm");
QApplication a(argc, argv);
a.installTranslator(&translator);
离线lebesgue06

只看该作者 8楼 发表于: 2012-02-16
新版本的好像变了吧,函数参数不一样了

QMessageBox::information ( QWidget * parent, const QString & title, const QString &text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ) [static]


QMessageBox *msgBox
msgBox->addButton();
快速回复
限100 字节
 
上一个 下一个