Dynamic retranslate UI. Button gets not arranged properly
-
So I have this app were I can change in a settings window dynamically the language. Everything fine except one Issue:
If I change from Spanish:
To german:
You can See that the Button in the bottom right (saying SCHLIEßEN) is not arranged well.
If I reopen the popup now issue it gets fixed:
Is this some kind of bug we have to live with or is there a solution for this?
Here is the code for this popup:
import QtQuick 2.15 import QtQuick.Layouts 1.15 import QtQuick.Controls 2.15 import LanguageSelectors 1.0 Dialog { id: root x: 100 y: 100 width: 400 height: 600 modal: true focus: true closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent title: qsTr("Settings") property alias countOfQuestions: countOfQuestionsSpinBox.value property bool darkModeOn ColumnLayout { id: columnLayout RowLayout { Label { text: qsTr("Light") font.pointSize: 13.5 } Switch { id: colorModeSwitch position: darkModeOn ? 1.0 : 0.0 onPositionChanged: { if (position === 0.0) { root.darkModeOn = false } else { root.darkModeOn = true } } } Label { text: qsTr("Dark") font.pointSize: 13.5 } } RowLayout { Label { text: qsTr("Count of Questions:") font.pointSize: 13.5 } SpinBox { Layout.fillWidth: true id: countOfQuestionsSpinBox from: 0 to: 999 editable: true } } RadioButton { checked: LanguageSelector.language === LanguageSelector.German text: qsTr("German") onPressed: { LanguageSelector.language = LanguageSelector.German } } RadioButton { checked: LanguageSelector.language === LanguageSelector.English text: qsTr("English") onPressed: { LanguageSelector.language = LanguageSelector.English } } RadioButton { checked: LanguageSelector.language === LanguageSelector.Spanish text: qsTr("Spanish") onPressed: { LanguageSelector.language = LanguageSelector.Spanish } } } standardButtons: Dialog.Close }
I change the language by assigning to languageSelector:
class LanguageSelector : public QObject { Q_OBJECT Q_PROPERTY(Language language READ language WRITE setLanguage NOTIFY languageChanged) public: enum Language { German, English, Spanish }; Q_ENUM(Language) explicit LanguageSelector(QObject *parent = nullptr); Language language() const; void setLanguage(Language newLanguage); QTranslator *getTranslator() const; private: QTranslator *mAppTranslator; QTranslator *mQtBaseTranslator; QTranslator *mQtQuickControlsTranslator; Language mLanguage; void loadGerman(); void loadEnglish(); void loadSpanish(); void loadLanguage(const QLocale::Language &newLanguage); signals: void languageChanged(); };
LanguageSelector is registered to qml as a singleton:
qmlRegisterSingletonInstance<LanguageSelector>( "LanguageSelectors", 1, 0, "LanguageSelector", languageSelector.get());
And connected to retranslate like this:
const QUrl url(QStringLiteral("qrc:/qml/main.qml")); QObject::connect( &engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); QObject::connect(languageSelector.get(), &LanguageSelector::languageChanged, &engine, &QQmlApplicationEngine::retranslate); engine.load(url);
Am I doing wrong here? Or is there some kind of trick to tell the button to get the proper position?
-
Could it be that this is a bug that implicit width is not properly recalculated when the retranslate happens?
-
I checked the issue and on Windows 10 it does not appear.
Only on my System with Manjaro Linux with KDE Plasma it happens.