QFileDialog
is used in my code like following:
QFileDialog fileDlg;
fileDlg.setFileMode(QFileDialog::AnyFile);
fileDlg.setViewMode(QFileDialog::
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.
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.
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.