1
0

qt: allow changing light/dark theme at runtime

Looks like the stylesheet can be changed at any time...
so we don't need to ask the user to restart the program.

closes https://github.com/spesmilo/electrum/issues/7209
This commit is contained in:
SomberNight
2022-02-18 18:08:38 +01:00
parent 96fcf68d84
commit 11a04c0d72
2 changed files with 8 additions and 3 deletions

View File

@@ -133,7 +133,10 @@ class ElectrumGui(BaseElectrumGui, Logger):
self._init_tray()
self.app.new_window_signal.connect(self.start_new_window)
self.app.quit_signal.connect(self.app.quit, Qt.QueuedConnection)
self.set_dark_theme_if_needed()
# maybe set dark theme
self._default_qtstylesheet = self.app.styleSheet()
self.reload_app_stylesheet()
run_hook('init_qt', self)
def _init_tray(self):
@@ -143,7 +146,7 @@ class ElectrumGui(BaseElectrumGui, Logger):
self.build_tray_menu()
self.tray.show()
def set_dark_theme_if_needed(self):
def reload_app_stylesheet(self):
use_dark_theme = self.config.get('qt_gui_color_theme', 'default') == 'dark'
if use_dark_theme:
try:
@@ -152,6 +155,8 @@ class ElectrumGui(BaseElectrumGui, Logger):
except BaseException as e:
use_dark_theme = False
self.logger.warning(f'Error setting dark theme: {repr(e)}')
else:
self.app.setStyleSheet(self._default_qtstylesheet)
# Apply any necessary stylesheet patches
patch_qt_stylesheet(use_dark_theme=use_dark_theme)
# Even if we ourselves don't set the dark theme,

View File

@@ -259,7 +259,7 @@ class SettingsDialog(WindowModalDialog):
colortheme_label = QLabel(_('Color theme') + ':')
def on_colortheme(x):
self.config.set_key('qt_gui_color_theme', colortheme_combo.itemData(x), True)
self.need_restart = True
self.window.gui_object.reload_app_stylesheet()
colortheme_combo.currentIndexChanged.connect(on_colortheme)
gui_widgets.append((colortheme_label, colortheme_combo))