@@ -46,6 +46,7 @@ private slots:
4646 void projectFilterNamesSurviveEditingAndTabSwitching ();
4747 void themesRender_data ();
4848 void themesRender ();
49+ void themeSwitchUpdatesExistingWidgets ();
4950 void cancelThemeCustomizationPreservesSettings ();
5051 void sampleWorkflowRenders_data ();
5152 void sampleWorkflowRenders ();
@@ -192,6 +193,53 @@ void MainWindowTest::newWorkspaceUsesSelectedFolder_data() {
192193 QTest::newRow (" tutorial" ) << true ;
193194}
194195
196+ namespace {
197+ void select_theme (MainWindow& window, const char * preset) {
198+ for (auto * action : window.findChildren <QAction*>()) {
199+ if (action->data ().toString () == preset && action->isCheckable ()) action->trigger ();
200+ }
201+ QApplication::processEvents ();
202+ }
203+
204+ bool widgets_match_theme (MainWindow& window, const char * preset) {
205+ const auto expected = theme_palette (preset, {}, system_theme_palette ());
206+ auto * filter = window.findChild <QLineEdit*>(" taskFilter" );
207+ return filter->palette ().color (QPalette::Base) == expected.color (QPalette::Base)
208+ && filter->palette ().color (QPalette::Text) == expected.color (QPalette::Text)
209+ && window.findChild <QStackedWidget*>(" detailStack" )->palette ().color (QPalette::WindowText) == expected.color (QPalette::WindowText)
210+ && window.findChild <QTextEdit*>()->palette ().color (QPalette::Base) == expected.color (QPalette::Base);
211+ }
212+ }
213+
214+ void MainWindowTest::themeSwitchUpdatesExistingWidgets () {
215+ QTemporaryDir temporary;
216+ const auto root = std::filesystem::path (temporary.path ().toStdString ()) / " theme-switch" ;
217+ QVERIFY (seed_task (root));
218+ {
219+ MainWindow window;
220+ window.open_workspace (root);
221+ window.resize (1280 , 820 );
222+ auto * tree = window.findChild <QTreeView*>(" taskTree" );
223+ tree->setCurrentIndex (tree->model ()->index (0 , 0 ));
224+ window.show ();
225+ for (const auto * preset : {" brown" , " light" , " brown" , " rose" , " light" }) {
226+ select_theme (window, preset);
227+ QVERIFY (widgets_match_theme (window, preset));
228+ }
229+ const auto directory = qEnvironmentVariable (" TODOBENCH_THEME_SCREENSHOTS" );
230+ if (!directory.isEmpty ()) {
231+ std::filesystem::create_directories (directory.toStdString ());
232+ QVERIFY (window.grab ().save (directory + " /switched-light.png" ));
233+ }
234+ }
235+ QCOMPARE (std::get<Settings>(load_settings (root / " settings.json" )).theme , std::string (" light" ));
236+ MainWindow reopened;
237+ reopened.open_workspace (root);
238+ reopened.show ();
239+ QApplication::processEvents ();
240+ QVERIFY (widgets_match_theme (reopened, " light" ));
241+ }
242+
195243void MainWindowTest::newWorkspaceUsesSelectedFolder () {
196244 QFETCH (bool , tutorial);
197245 QTemporaryDir temporary;
0 commit comments