src/eric7/EricWidgets/EricApplication.py

branch
eric7
changeset 9976
ceae971872de
parent 9653
e67609152c5e
child 9995
00eb2b418f8e
diff -r ac49f16d2a9b -r ceae971872de src/eric7/EricWidgets/EricApplication.py
--- a/src/eric7/EricWidgets/EricApplication.py	Tue Apr 11 11:34:52 2023 +0200
+++ b/src/eric7/EricWidgets/EricApplication.py	Wed Apr 12 13:10:09 2023 +0200
@@ -7,6 +7,7 @@
 Class implementing a specialized application class.
 """
 
+import contextlib
 import os
 
 from PyQt6.QtCore import QCoreApplication, Qt
@@ -70,6 +71,9 @@
                 primaryScreenSize.width() < 1920 or primaryScreenSize.height() < 1080
             )
 
+        self.__hasNonStandardPalette = False
+        self.__hasUserStyleSheet = False
+
     def usesSmallScreen(self):
         """
         Public method to determine, if the application is used on a small
@@ -238,6 +242,8 @@
             styleIconsPath = self.getStyleIconsPath(universal=True)
             styleSheet = styleSheet.replace("${path}", styleIconsPath)
 
+            self.__hasUserStyleSheet = True
+
         if "QPalette {" in styleSheet:
             self.__setPaletteFromStyleSheet(styleSheet)
 
@@ -263,6 +269,8 @@
 
         self.setPalette(palette)
 
+        self.__hasNonStandardPalette = True
+
     def usesDarkPalette(self):
         """
         Public method to check, if the application uses a palette with a dark
@@ -271,9 +279,16 @@
         @return flag indicating the use of a palette with a dark background
         @rtype bool
         """
+        if not self.__hasNonStandardPalette:
+            with contextlib.suppress(AttributeError):
+                return self.styleHints().colorScheme() == Qt.ColorScheme.Dark
+
+        # backward compatibility for Qt < 6.5.0 or changed by user
         palette = self.palette()
-        lightness = palette.color(QPalette.ColorRole.Window).lightness()
-        return lightness <= 128
+        return (
+            palette.color(QPalette.ColorRole.WindowText).lightness() >
+            palette.color(QPalette.ColorRole.Window).lightness()
+        )
 
 
 ericApp = QCoreApplication.instance

eric ide

mercurial