From 5f6be29f66f1c482322cb9814bb603947378352d Mon Sep 17 00:00:00 2001 From: Kiu Shueng Chuan Date: Fri, 26 Feb 2021 10:28:09 +0800 Subject: [PATCH] connect paletteChanged to standalone function --- pyqtgraph/Qt.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pyqtgraph/Qt.py b/pyqtgraph/Qt.py index 142b3f30..f3b0f5cb 100644 --- a/pyqtgraph/Qt.py +++ b/pyqtgraph/Qt.py @@ -464,16 +464,8 @@ if m is not None and list(map(int, m.groups())) < versionReq: print(list(map(int, m.groups()))) raise Exception('pyqtgraph requires Qt version >= %d.%d (your version is %s)' % (versionReq[0], versionReq[1], QtVersion)) -class App(QtGui.QApplication): - - def __init__(self, *args, **kwargs): - super(App, self).__init__(*args, **kwargs) - self.paletteChanged.connect(self.onPaletteChange) - self.onPaletteChange(self.palette()) - - def onPaletteChange(self, palette): - color = palette.base().color().name() - self.setProperty('darkMode', color.lower() != "#ffffff") +App = QtWidgets.QApplication +# subclassing QApplication causes segfaults on PySide{2, 6} / Python 3.8.7+ QAPP = None def mkQApp(name=None): @@ -487,6 +479,11 @@ def mkQApp(name=None): """ global QAPP + def onPaletteChange(palette): + color = palette.base().color().name() + app = QtWidgets.QApplication.instance() + app.setProperty('darkMode', color.lower() != "#ffffff") + QAPP = QtGui.QApplication.instance() if QAPP is None: # hidpi handling @@ -500,7 +497,9 @@ def mkQApp(name=None): else: # qt 5.12 and 5.13 QtGui.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) QtGui.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps) - QAPP = App(sys.argv or ["pyqtgraph"]) + QAPP = QtGui.QApplication(sys.argv or ["pyqtgraph"]) + QAPP.paletteChanged.connect(onPaletteChange) + QAPP.paletteChanged.emit(QAPP.palette()) if name is not None: QAPP.setApplicationName(name)