Changed some more widgets to work with style sheets instead of manipulating the palette. eric7

Sat, 25 Dec 2021 11:24:30 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 25 Dec 2021 11:24:30 +0100
branch
eric7
changeset 8854
68c67538da4e
parent 8853
efcceef1e26b
child 8855
6bd9f3d7896e

Changed some more widgets to work with style sheets instead of manipulating the palette.

eric7/Preferences/ConfigurationPages/EditorStylesPage.py file | annotate | diff | comparison | revisions
--- a/eric7/Preferences/ConfigurationPages/EditorStylesPage.py	Fri Dec 24 16:36:44 2021 +0100
+++ b/eric7/Preferences/ConfigurationPages/EditorStylesPage.py	Sat Dec 25 11:24:30 2021 +0100
@@ -8,7 +8,7 @@
 """
 
 from PyQt6.QtCore import pyqtSlot
-from PyQt6.QtGui import QColor, QPalette
+from PyQt6.QtGui import QColor
 from PyQt6.QtWidgets import QColorDialog, QFontDialog
 from PyQt6.Qsci import QsciScintilla
 
@@ -427,7 +427,24 @@
         self.monospacedFont = self.selectFont(
             self.monospacedFontSample, self.monospacedFont,
             options=QFontDialog.FontDialogOption.MonospacedFonts)
+    
+    def __setSampleStyleSheet(self, sampleLineEdit, color, background):
+        """
+        Private method to colorize a sample with given foreground and
+        background colors.
         
+        @param sampleLineEdit line edit element to be colorized
+        @type QLineEdit
+        @param color text color to be shown
+        @type QColor
+        @param background background color to be shown
+        @type QColor
+        """
+        sampleLineEdit.setStyleSheet(
+            "QLineEdit {{ color: {0}; background-color: {1}; }}"
+            .format(color.name(), background.name())
+        )
+    
     def polishPage(self):
         """
         Public slot to perform some polishing actions.
@@ -436,29 +453,20 @@
         self.defaultFontSample.setFont(self.defaultFont)
         self.monospacedFontSample.setFont(self.monospacedFont)
         
-        pl = self.annotationsWarningSample.palette()
-        pl.setColor(QPalette.ColorRole.Text,
-                    self.editorColours["AnnotationsWarningForeground"])
-        pl.setColor(QPalette.ColorRole.Base,
-                    self.editorColours["AnnotationsWarningBackground"])
-        self.annotationsWarningSample.setPalette(pl)
-        self.annotationsWarningSample.repaint()
+        self.__setSampleStyleSheet(
+            self.annotationsWarningSample,
+            self.editorColours["AnnotationsWarningForeground"],
+            self.editorColours["AnnotationsWarningBackground"])
         
-        pl = self.annotationsErrorSample.palette()
-        pl.setColor(QPalette.ColorRole.Text,
-                    self.editorColours["AnnotationsErrorForeground"])
-        pl.setColor(QPalette.ColorRole.Base,
-                    self.editorColours["AnnotationsErrorBackground"])
-        self.annotationsErrorSample.setPalette(pl)
-        self.annotationsErrorSample.repaint()
+        self.__setSampleStyleSheet(
+            self.annotationsErrorSample,
+            self.editorColours["AnnotationsErrorForeground"],
+            self.editorColours["AnnotationsErrorBackground"])
         
-        pl = self.annotationsStyleWarningSample.palette()
-        pl.setColor(QPalette.ColorRole.Text,
-                    self.editorColours["AnnotationsStyleForeground"])
-        pl.setColor(QPalette.ColorRole.Base,
-                    self.editorColours["AnnotationsStyleBackground"])
-        self.annotationsStyleWarningSample.setPalette(pl)
-        self.annotationsStyleWarningSample.repaint()
+        self.__setSampleStyleSheet(
+            self.annotationsStyleWarningSample,
+            self.editorColours["AnnotationsStyleForeground"],
+            self.editorColours["AnnotationsStyleBackground"])
     
     @pyqtSlot()
     def on_annotationsWarningFgButton_clicked(self):
@@ -468,10 +476,10 @@
         colour = QColorDialog.getColor(
             self.editorColours["AnnotationsWarningForeground"])
         if colour.isValid():
-            pl = self.annotationsWarningSample.palette()
-            pl.setColor(QPalette.ColorRole.Text, colour)
-            self.annotationsWarningSample.setPalette(pl)
-            self.annotationsWarningSample.repaint()
+            self.__setSampleStyleSheet(
+                self.annotationsWarningSample,
+                colour,
+                self.editorColours["AnnotationsWarningBackground"])
             self.editorColours["AnnotationsWarningForeground"] = colour
     
     @pyqtSlot()
@@ -482,10 +490,10 @@
         colour = QColorDialog.getColor(
             self.editorColours["AnnotationsWarningBackground"])
         if colour.isValid():
-            pl = self.annotationsWarningSample.palette()
-            pl.setColor(QPalette.ColorRole.Base, colour)
-            self.annotationsWarningSample.setPalette(pl)
-            self.annotationsWarningSample.repaint()
+            self.__setSampleStyleSheet(
+                self.annotationsWarningSample,
+                self.editorColours["AnnotationsWarningForeground"],
+                colour)
             self.editorColours["AnnotationsWarningBackground"] = colour
     
     @pyqtSlot()
@@ -496,10 +504,10 @@
         colour = QColorDialog.getColor(
             self.editorColours["AnnotationsErrorForeground"])
         if colour.isValid():
-            pl = self.annotationsErrorSample.palette()
-            pl.setColor(QPalette.ColorRole.Text, colour)
-            self.annotationsErrorSample.setPalette(pl)
-            self.annotationsErrorSample.repaint()
+            self.__setSampleStyleSheet(
+                self.annotationsErrorSample,
+                colour,
+                self.editorColours["AnnotationsErrorBackground"])
             self.editorColours["AnnotationsErrorForeground"] = colour
     
     @pyqtSlot()
@@ -510,10 +518,10 @@
         colour = QColorDialog.getColor(
             self.editorColours["AnnotationsErrorBackground"])
         if colour.isValid():
-            pl = self.annotationsErrorSample.palette()
-            pl.setColor(QPalette.ColorRole.Base, colour)
-            self.annotationsErrorSample.setPalette(pl)
-            self.annotationsErrorSample.repaint()
+            self.__setSampleStyleSheet(
+                self.annotationsErrorSample,
+                self.editorColours["AnnotationsErrorForeground"],
+                colour)
             self.editorColours["AnnotationsErrorBackground"] = colour
     
     @pyqtSlot()
@@ -524,10 +532,10 @@
         colour = QColorDialog.getColor(
             self.editorColours["AnnotationsStyleForeground"])
         if colour.isValid():
-            pl = self.annotationsStyleWarningSample.palette()
-            pl.setColor(QPalette.ColorRole.Text, colour)
-            self.annotationsStyleWarningSample.setPalette(pl)
-            self.annotationsStyleWarningSample.repaint()
+            self.__setSampleStyleSheet(
+                self.annotationsStyleWarningSample,
+                colour,
+                self.editorColours["AnnotationsStyleBackground"])
             self.editorColours["AnnotationsStyleForeground"] = colour
     
     @pyqtSlot()
@@ -538,11 +546,11 @@
         colour = QColorDialog.getColor(
             self.editorColours["AnnotationsStyleBackground"])
         if colour.isValid():
-            pl = self.annotationsStyleWarningSample.palette()
-            pl.setColor(QPalette.ColorRole.Base, colour)
-            self.annotationsStyleWarningSample.setPalette(pl)
-            self.annotationsStyleWarningSample.repaint()
-            self.editorColours["AnnotationsStyleackground"] = colour
+            self.__setSampleStyleSheet(
+                self.annotationsStyleWarningSample,
+                self.editorColours["AnnotationsStyleForeground"],
+                colour)
+            self.editorColours["AnnotationsStyleBackground"] = colour
 
 
 def create(dlg):

eric ide

mercurial