Skip to content

Commit 678d138

Browse files
committed
Add custom QMainWindow to handle OS theme update events.
1 parent bc3cba8 commit 678d138

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

runviewer/__main__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import h5py
4747

4848
# No splash update for Qt - the splash screen already imported it
49-
from qtutils.qt import QtCore, QtGui, QtWidgets
49+
from qtutils.qt import QtCore, QtGui, QtWidgets, QT_ENV
5050
from qtutils import UiLoader, inmain_later, inmain_decorator
5151

5252
splash.update_text('importing pyqtgraph')
@@ -192,11 +192,24 @@ def setModelData(self, editor, model, index):
192192
def updateEditorGeometry(self, editor, option, index):
193193
editor.setGeometry(option.rect)
194194

195+
class RunviewerMainWindow(QtWidgets.QMainWindow):
196+
197+
def changeEvent(self, event):
198+
199+
# theme update only for PySide6
200+
if QT_ENV == 'PySide6' and event.type() == QtCore.QEvent.Type.ThemeChange:
201+
for widget in self.findChildren(QtWidgets.QWidget):
202+
# Complex widgets, like TreeView and TableView require triggering styleSheet and palette updates
203+
widget.setStyleSheet(widget.styleSheet())
204+
widget.setPalette(widget.palette())
205+
206+
return super().changeEvent(event)
207+
195208

196209
class RunViewer(object):
197210
def __init__(self, exp_config):
198211
splash.update_text('loading graphical interface')
199-
self.ui = UiLoader().load(os.path.join(runviewer_dir, 'main.ui'))
212+
self.ui = UiLoader().load(os.path.join(runviewer_dir, 'main.ui'), RunviewerMainWindow())
200213

201214
# setup shot treeview model
202215
self.shot_model = QtGui.QStandardItemModel()

0 commit comments

Comments
 (0)