From 147b08ecf810af7a601acb144ba1a0dcb0648453 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 2 Jul 2023 23:54:55 +0200 Subject: [PATCH] Retranslate tab texts in settings dialog dynamically --- settingsdialog/settingsdialog.cpp | 13 +++++++++++++ settingsdialog/settingsdialog.h | 1 + 2 files changed, 14 insertions(+) diff --git a/settingsdialog/settingsdialog.cpp b/settingsdialog/settingsdialog.cpp index e211f60..4cb7d9f 100644 --- a/settingsdialog/settingsdialog.cpp +++ b/settingsdialog/settingsdialog.cpp @@ -288,6 +288,18 @@ void SettingsDialog::updateTabWidget() m_ui->pagesTabWidget->setUpdatesEnabled(true); } +/*! + * \brief Updates the tab widget's tab texts to apply possible translation changes. + */ +void SettingsDialog::retranslateTabWidget() +{ + for (auto index = 0; index < m_ui->pagesTabWidget->count(); ++index) { + const auto *const scrollArea = qobject_cast(m_ui->pagesTabWidget->widget(index)); + const auto *const widget = scrollArea->widget(); + m_ui->pagesTabWidget->setTabText(index, widget->windowTitle()); + } +} + /*! * \brief Applies all changes. Calls OptionCategory::applyAllPages() for each category. * \remarks Pages which have not been shown yet must have not been initialized anyways @@ -354,6 +366,7 @@ bool SettingsDialog::event(QEvent *event) break; case QEvent::LanguageChange: m_ui->retranslateUi(this); + retranslateTabWidget(); emit retranslationRequired(); break; default:; diff --git a/settingsdialog/settingsdialog.h b/settingsdialog/settingsdialog.h index e0c2545..4d71e1a 100644 --- a/settingsdialog/settingsdialog.h +++ b/settingsdialog/settingsdialog.h @@ -54,6 +54,7 @@ protected: private Q_SLOTS: void currentCategoryChanged(const QModelIndex &index); void updateTabWidget(); + void retranslateTabWidget(); private: std::unique_ptr m_ui;