Retranslate tab texts in settings dialog dynamically

This commit is contained in:
Martchus 2023-07-02 23:54:55 +02:00
parent 0392b27b97
commit 147b08ecf8
2 changed files with 14 additions and 0 deletions

View File

@ -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<const QScrollArea *>(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:;

View File

@ -54,6 +54,7 @@ protected:
private Q_SLOTS:
void currentCategoryChanged(const QModelIndex &index);
void updateTabWidget();
void retranslateTabWidget();
private:
std::unique_ptr<Ui::SettingsDialog> m_ui;