1

When I have changeEvent(QEvent* event) with receive type event->type() == QEvent::LanguageChange, how can I get information about what the new language is in my app?

Tay2510
  • 5,748
  • 7
  • 39
  • 58
HelloThere
  • 35
  • 1
  • 5

2 Answers2

0

You can compare the translated string with its known translations:

void changeEvent(QEvent *event)
{
    if (event->type() == QEvent::LanguageChange) {
        QString translated = QCoreApplication::translate("some context", "Button");
        if (translated == "Button")
            // language is English
        else if (translated == "Кнопка")
            // language is Russian
        ...
    }
}
svlasov
  • 9,923
  • 2
  • 38
  • 39
0

Qt don't have any object to represent application langugae. So you should implement it yorself.

Usually changeEvent(QEvent* event) with type QEvent::LanguageChange was caused by installTranslator(QTranslator*) so you should know witch langugae you loaded to translator and store it locally.

Ruslan F.
  • 5,498
  • 3
  • 23
  • 42