[Qt-interest] To apply internationalization to menu and sub-menu items
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Wed Feb 11 14:14:38 CET 2009
Hemalatha Venkataswamy wrote on Wednesday, February 11, 2009 9:01 AM:
> Hi,
>
> I have incorporated internationalization in my project. I choose the
> desired language from the combo-box and on close of my dialog, the
> language is applied to all the dialogs and main window also. But I m
> unable to apply to the menu items. I also used update() function
> after choosing the lanaguge, but it did not work.
QWidget::update() does not re-set the texts, it simply tells Qt: "Draw (update) this widget at some point later in time (when the Qt event loop feels like to do so)".
The trick is you need to re-set the texts in the QActions which you have added to the menus. So whenever you get a "language change" event you need to iterate over all the QActions and call:
action->setText(tr("Text to be translated"));
Only the tr() function does the proper translation (once you have the proper *.qm file loaded).
I would have expected that when you create a QMainWindow with menus with the Qt Designer, that the appropriate code is already generated by the uic - is that not the case? If so, just have a look at the generated code for some inspiration, how to react to the "language changed" event and how to update all the QActions.
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list