QFileDialog localization

前端 未结 3 1994
傲寒
傲寒 2020-12-12 01:01

QFileDialog is used in my code like following:

QFileDialog fileDlg;
fileDlg.setFileMode(QFileDialog::AnyFile);
fileDlg.setViewMode(QFileDialog::         


        
相关标签:
3条回答
  • 2020-12-12 01:02

    I know this has been answered and accepted but the correct way is not to manually translate what Qt already provides but rather to load the translations included in Qt like this:

     /* load the system translations provided by Qt */
     QTranslator qtTranslator;
     qtTranslator.load("qt_" + QLocale::system().name(),
             QLibraryInfo::location(QLibraryInfo::TranslationsPath));
     app.installTranslator(&qtTranslator);
    
     /* load our custom translations for this application */
     QTranslator myappTranslator;
     myappTranslator.load("myapp_" + QLocale::system().name());
     app.installTranslator(&myappTranslator);
    

    This way Qt will translate what it already knows (like it's own widgets) and will use the custom translations provided with the application for the rest.

    0 讨论(0)
  • 2020-12-12 01:04

    You can use one of the static functions in QFileDialog. Those use the native file dialog from the OS, which will be in the correct locale and translation.

    0 讨论(0)
  • 2020-12-12 01:27

    The "Open" string is hardcoded but translated in QFileDialog:

    void QFileDialogPrivate::_q_updateOkButton()
    {
    // ...
        if (acceptMode == QFileDialog::AcceptSave)
            button->setText(isOpenDirectory ? QFileDialog::tr("&Open") : acceptLabel);
    

    You'll need to install a QTranslator that translates &Open in the QFileDialog context to what you want.

    Also see Internationalization in Qt docs for more info.

    0 讨论(0)
提交回复
热议问题