[Solved] QEvent::LanguageChange
-
Hi,
How are you changing the language ?
-
How are you installing your filter object ?
-
Why would I need to install a filter object? I mean, it is not like I don't want them...
Nevertheless, the EventFilter is never called if I install it like this:
LanguageNotifier::LanguageNotifier(QObject *parent) : QObject(parent) { installEventFilter(this); } bool LanguageNotifier::eventFilter(QObject *obj, QEvent *event) { qDebug() << Q_FUNC_INFO << event->type(); if (event->type() == QEvent::LanguageChange) { return false; } return QObject::eventFilter(obj, event); }
-
That's not what I meant. If I understand you correctly, LanguageNotifier should work like the KeyPressEater of installEventFilter's documentation, right ?
-
Not necessarily. My plan is to have multiple QObjects with dedicated listener QML clients, which get notified on a global language change. From experience I know that with QWidget I can listen to the LanguageChange event, but the problem is that neither event() nor an installed eventFilter receives a LanguageChange event in a QObject implementation.
Of course, if Qt does not distribute LanguageChange to non-widgets, that I need to implement my own language change distribution system, but what I don't understand is that I should.
-
We might say that QWidget is a special case. It makes sense for a QWidget to receive events related to GUI, but it wouldn't make sense for Qt to send every event to every existing QObject.
However you can set your LanguageNotifier as filter on QApplication/QGuiApplication and then you'll be able to handle these events the way you want.
-
Nice! That worked. Thank you.
For those who are interested:
main.cpp
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); LanguageNotifier languageNotifier; app.installEventFilter(&languageNotifier); ... }
LanguageNotifier.cpp
bool LanguageNotifier::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::LanguageChange) { emit languageChanged(); return false; } return QObject::eventFilter(obj, event); }
-
Didn't you forgot to declare languageNotifier ? ;)