QFileDialog动态翻译 [英] QFileDialog dynamic translation

查看:423
本文介绍了QFileDialog动态翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题有不幸地被问过,但我在这里疯了。
在我的Qt应用程序,用户能够动态更改语言,适合我所有的翻译。它不工作对我的调用QFileDialog。相应的代码:

  void myapp :: change_language(std :: string& lang_str){
//我自己translations works
qApp-> removeTranslator(& this-> app_lang);
this-> app_lang.load(QString :: fromStdString(lang_str));
qApp-> installTranslator(& this-> app_lang);

//系统翻译,不适用于qfiledialog
qApp-> removeTranslator(& this-> app_lang_qt);
bool test = this-> app_lang_qt.load(qt_fr.qm); // returns true
qApp-> installTranslator(& this-> app_lang_qt);
}

  void myapp :: changeEvent(QEvent * event){
if(event-> type()== QEvent :: LanguageChange){
this-> ui .retranslateUi(this);
}
QMainWindow :: changeEvent(event);
}

使用

  QTranslator app_lang; 
QTranslator app_lang_qt;

固定字符串qt_fr.qm仅用于测试目的, p>

我想要的是改变静态调用的语言QFileDialog和QMessageBox,但语言只改变在QMessageBox,而不是在QFileDialog。对于这两个类,我只调用静态成员,这不是问题。我也试着在main.cpp中安装这个翻译器,结果相同。

解决方案

默认情况下,QFileDialog会使用native文件浏览器而不是基于自定义Qt的对话框。本地文件浏览器将使用操作系统语言,而不是Qt语言,并且不会应用Qt翻译。您可以使用 QFileDialog DontUseNativeDialog 选项覆盖此行为。


This question has unfortunately been asked before but I'm going insane here. In my Qt Application the user is able to dynamically change the language which works perfect for all my own translations. It does not work for my calls to QFileDialog. The respective code:

void myapp::change_language(std::string& lang_str){
    // my own translations works
    qApp->removeTranslator(&this->app_lang);
    this->app_lang.load(QString::fromStdString(lang_str));
    qApp->installTranslator(&this->app_lang);

    // system translations, works not for qfiledialog
    qApp->removeTranslator(&this->app_lang_qt);
    bool test = this->app_lang_qt.load("qt_fr.qm"); // returns true
    qApp->installTranslator(&this->app_lang_qt);
}

And

void myapp::changeEvent(QEvent* event){
    if(event->type() == QEvent::LanguageChange){
        this->ui.retranslateUi(this);
    }
    QMainWindow::changeEvent(event);
}

With

QTranslator app_lang;
QTranslator app_lang_qt;

The fixed string "qt_fr.qm" is just for testing purpose because french is easily detectable.

What I want is to change the language in static calls to QFileDialog and QMessageBox but the language is only changed in QMessageBox, not in QFileDialog. For both classes I'm only calling the static members to that can't be the issue. I also tried to install this translator in the main.cpp with the same results.

解决方案

By default, QFileDialog will use the native file browser rather than a custom Qt-based dialog. The native file browser is will be using the OS language, rather than the Qt language, and will not have Qt translations applied to it. You can override this behaviour using the DontUseNativeDialog option for QFileDialog.

这篇关于QFileDialog动态翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆