Re: QTranslator: the menu is not translated
I'm working on a GUI that uses QTranslator and everything works fine.
I load the language at start up and can change it on the fly.
The only problem is that the menu (menuBar) is not translated when the language is switched.
If I save the options and restart the GUI, then the menu is in the right language but if I
change the language on the fly, the menu is not translated.
I create the menu after having installed the translator.
I create all the menus/actions with the tr("name") function.
What am I missing ?
thanks
Added after 18 minutes:
Another question: is it possible to run lupdate automatically from the makefile ?
If yes, what should I write in the .pro file ?
Re: QTranslator: the menu is not translated
Are you putting "shortcut" characters into the menu item strings? If so, it could be that the translator is not finding an exact match, so does not make a translation.
Re: QTranslator: the menu is not translated
Yes, of course I put shortcuts. Anyway, it's not nice but I've solved with an UpdateMenus() function, thanks.
Re: QTranslator: the menu is not translated
Do you handle LanguageChange event for the widget that adds items to the menus?
Re: QTranslator: the menu is not translated
Yes, I do.
Code:
void MainWindow
::changeEvent(QEvent* event
) {
if (event
->type
() == QEvent::LanguageChange) {
ui->retranslateUi(this);
SetTablesFields();
UpdateMenus();
if (m_DBGui)
m_DBGui->Retranslate();
if (m_LogGui)
m_LogGui->Retranslate();
if (m_PluginOptionsGui)
m_PluginOptionsGui->Retranslate();
}
}
///////////////////////////////////////////////////////////////
Re: QTranslator: the menu is not translated
That's the proper way of retranslating widgets.
Re: QTranslator: the menu is not translated
Good to know that it's done in a proper way, thanks... so at least I know it's not my fault :D
Re: QTranslator: the menu is not translated
Just the name "UpdateMenus()" is a bit wrong here. Call it retranslateMenus() and also call it the first time you set items to the menu. Have a look at code generated by Designer, it has a similar method.