QFileDialog dynamic translation

耗尽温柔 提交于 2019-12-12 05:34:06

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/22749267/qfiledialog-dynamic-translation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!