[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:42:39 CET 2009


Knoll Oliver, ITS-CMT-SUI-SL-PDC-FIN-DEV wrote on Wednesday, February 11, 2009 2:15 PM:

> ...
> 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?

And in fact that's the case. When you have a look at the generated code, coming from a QMainWindow with menu entries (as designed in Qt Designer), in "ui_MyMainWindow.h" you will see a

  retranslateUi(...)

method. This method is already called in the setupUi() method (which your code usually calls in your c'tor of your QMainWindow implemenation) and just does as I suggested before: it re-sets the text (using tr()) for any GUI element (QActions, QLabels, ...).

What I don't quite understand right now how the generated code reacts to "language change" events - I think it simply doesn't. At least in Qt 3 days I think the uic compiler also generated such code - but I don't see any reference to a "language change" event right now (Qt 4).

Anyway, it is easy to catch these events in your actual QMainWindow implementation class and then you should be able to call retranslateUi() (just as you call setupUi() in your c'tor). I wouldn't be surprised if all this was documented in some "Qt i18n tutorial somewhere out there" ;)

If on the other hand you "handcoded" your menu setup: just do as the generated code.

Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list