I’m using the static QMessageBox functions for a small download tool I wrote. Unfortunately, I struggled a little bit with the translation of the OK and Cancel buttons. There is some information available by asking uncle google, but the information revealed seems not 100% correct for Qt 5.3.
What you need to do is to load the Qt translation file in addition to your original .qm file(s) at the same time you load your own translation file(s). The file is located in the translation sub-folder of your Qt installation folder. For the OK and Cancel buttons you would need to load the “qtbase_XX” where XX should be replaced with your locale:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
int main(int argc, char *argv[]) { QApplication a(argc, argv); // Own translation file QTranslator translator; translator.load(a.applicationName() + "_" + QLocale::system().name(), a.applicationDirPath()); a.installTranslator(&translator); // Translation file for Qt stuff QTranslator translator2; translator2.load("qtbase_" + QLocale::system().name(), a.applicationDirPath()); a.installTranslator(&translator2); MainWidget wid; wid.setWindowState(Qt::WindowMinimized); wid.show(); return a.exec(); } |
Original Qt FAQ:
Technical_FAQ#How_can_I_translate_the_OK_and_Cancel_buttons…
Hope this is of some help. I appreciate all comments, just use the comment box below.
Mike Bergmann
Latest posts by Mike Bergmann (see all)
- Rendering networkx graphs or graphml files via Mermaid - November 22, 2019
- Yocto recipe compiling Qt apps with cmake - July 21, 2019
- Check if your crross-compiler GCC toolchain is supporting hard-float - October 25, 2018
3 comments