Details
-
Suggestion
-
Resolution: Done
-
Not Evaluated
-
None
-
None
-
4cca8ee527 (qt/qtbase/dev) 4cca8ee527 (qt/tqtc-qtbase/dev) 70828223f3 (qt/qtbase/6.3) 70828223f3 (qt/tqtc-qtbase/6.3) 70828223f3 (qt/tqtc-qtbase/6.3.0)
Description
Add the disable option of layout direction setting function automatically. It works based on the translation file.
In the qtbase codes(qguiapplication.cpp) below, The layout direction is determined by the active language translation file.
That code is executed when QEvent::LanguageChange, sets the Layout Direction.
(https://doc.qt.io/qt-5/qtquick-positioning-righttoleft.html#default-layout-direction)
When language is applied,
1. CALL installTranslator()
https://code.woboq.org/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp.html#_ZN16QCoreApplication17installTranslatorEP11QTranslator
bool QCoreApplication::installTranslator(QTranslator *translationFile) { if (!translationFile) return false; if (!QCoreApplicationPrivate::checkInstance("installTranslator")) return false; QCoreApplicationPrivate *d = self->d_func(); { QWriteLocker locker(&d->translateMutex); d->translators.prepend(translationFile); } #ifndef QT_NO_TRANSLATION_BUILDER if (translationFile->isEmpty()) return false; #endif #ifndef QT_NO_QOBJECT QEvent ev(QEvent::LanguageChange); QCoreApplication::sendEvent(self, &ev); #endif return true; }
2. CALL QGuiApplication::event()
https://code.woboq.org/qt5/qtbase/src/gui/kernel/qguiapplication.cpp.html#1860
bool QGuiApplication::event(QEvent *e) { if(e->type() == QEvent::LanguageChange) { // // We don't want this code to run automatically // // setLayoutDirection(qt_detectRTLLanguage()?Qt::RightToLeft:Qt::LeftToRight); // for (auto *topLevelWindow : QGuiApplication::topLevelWindows()) { if (topLevelWindow->flags() != Qt::Desktop) postEvent(topLevelWindow, new QEvent(QEvent::LanguageChange)); } } else if (e->type() == QEvent::Quit) { ..
3. CALL qt_detectRTLLanguage()
https://code.woboq.org/qt5/qtbase/src/gui/kernel/qguiapplication.cpp.html#_ZL20qt_detectRTLLanguagev
static bool qt_detectRTLLanguage() { return force_reverse ^ (QGuiApplication::tr("QT_LAYOUT_DIRECTION", "Translate this string to the string 'LTR' in left-to-right" " languages or to 'RTL' in right-to-left languages (such as Hebrew" " and Arabic) to get proper widget layout.") == QLatin1String("RTL")); }
In the end, LAYOUT DIRECTION is set based on the language translation file.
We suggest the feature below.
It would be nice to be able to disable the function to automatically determine when a language is changed. Because The layout direction can change unexpectedly.
As you know, This is not a bug. We can set the layout direction by translation file. However, some users may not want to use QT_LAYOUT_DIRECTION string in the translation file.
We hope to be able to control whether to use the translation file based layout direction setting through build configuration.