如何在QT中翻译标准按钮?
我在qmessagebox中翻译标准按钮有问题。如果我检查语言,则按钮的翻译非常好,但是如果我不检查语言,则不会翻译按钮。我如何在需要显示Qmessagebox时每次检查语言而不检查语言的情况下如何获得翻译按钮?
#include "application.h"
#include "main_window.h"
#include <QTranslator>
#include <qlibraryinfo.h>
int main( int argc, char *argv[] )
{
Application application( argc, argv );
QString language = app()->settings().value("language").toString();
if (language == "Russian") // Here I check the language
{
QTranslator translator_ru;
if (translator_ru.load(QString("translations/qtbase_ru.qm")))
application.installTranslator(&translator_ru);
if (QMessageBox::question(0, "Delete?", "First test") == QMessageBox::Yes) {} // In this message, the standard buttons are in Russian
}
if (QMessageBox::question(0, "Delete?", "Second test") == QMessageBox::Yes) {} // In this message, the standard buttons are in English
MainWindow window;
window.show();
return application.exec();
}
I have a problem with translate standard buttons in QMessageBox. If I check the language, the buttons are translated very well, but if I don't check the language, the buttons are not translated. How can I get translated buttons without checking the language every time when I need to show QMessageBox?
#include "application.h"
#include "main_window.h"
#include <QTranslator>
#include <qlibraryinfo.h>
int main( int argc, char *argv[] )
{
Application application( argc, argv );
QString language = app()->settings().value("language").toString();
if (language == "Russian") // Here I check the language
{
QTranslator translator_ru;
if (translator_ru.load(QString("translations/qtbase_ru.qm")))
application.installTranslator(&translator_ru);
if (QMessageBox::question(0, "Delete?", "First test") == QMessageBox::Yes) {} // In this message, the standard buttons are in Russian
}
if (QMessageBox::question(0, "Delete?", "Second test") == QMessageBox::Yes) {} // In this message, the standard buttons are in English
MainWindow window;
window.show();
return application.exec();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案:
I've found the solution: