From 3a17596931879653d93cf74bb1425e000dc009f2 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 27 Nov 2021 02:11:40 -0500 Subject: [PATCH] Attempt to modify changeEvent for our dialogs, but not quite --- src/mainwindow.cpp | 19 +++++++++++++++++++ src/mainwindow.h | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7d35486..f63d038 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -22,6 +22,9 @@ #include "requestdialog.h" #include "websockets.h" +SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { +} + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -339,9 +342,25 @@ void MainWindow::setupStatusBar() { ui->statusBar->addPermanentWidget(statusIcon); } +// something like this is needed for QDialogs to listen to changeEvent +// so the Settings modal gets retranslated +// https://stackoverflow.com/questions/68665394/how-to-use-retranslateui-recursively-on-all-ui-in-qmainwindow +void SettingsDialog::changeEvent(QEvent* event) { + Ui_Settings settings; + qDebug() << __func__ << ":changeEvent type=" << event->type(); + if (event->type() == QEvent::LanguageChange) { + SettingsDialog settingsDialog(this); + settings.retranslateUi(&settingsDialog); + } + + QWidget::changeEvent(event); +} + void MainWindow::setupSettingsModal() { // Set up File -> Settings action QObject::connect(ui->actionSettings, &QAction::triggered, [=]() { + // this coredumps at run-time + //SettingsDialog settingsDialog(this); QDialog settingsDialog(this); Ui_Settings settings; settings.setupUi(&settingsDialog); diff --git a/src/mainwindow.h b/src/mainwindow.h index a6a6c13..a811665 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -32,6 +32,15 @@ namespace Ui { class MainWindow; } +class SettingsDialog : public QDialog +{ + Q_OBJECT +public: + explicit SettingsDialog(QWidget *parent = nullptr); + // this event is called, when a new translator is loaded or the system language is changed + void changeEvent(QEvent* event); +}; + class MainWindow : public QMainWindow { Q_OBJECT