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

Wed, 22 Dec 2021 19:54:10 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 22 Dec 2021 19:54:10 +0100
branch
eric7
changeset 8850
da93f2ba802f
parent 8849
cb2dfb596bd6
child 8851
707ad3f63301

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

eric7/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py file | annotate | diff | comparison | revisions
--- a/eric7/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py	Wed Dec 22 19:53:50 2021 +0100
+++ b/eric7/Preferences/ConfigurationPages/EditorHighlightingStylesPage.py	Wed Dec 22 19:54:10 2021 +0100
@@ -10,7 +10,7 @@
 import os
 
 from PyQt6.QtCore import pyqtSlot, Qt, QFileInfo, QFile, QIODevice
-from PyQt6.QtGui import QPalette, QFont, QColor
+from PyQt6.QtGui import QFont, QColor
 from PyQt6.QtWidgets import (
     QColorDialog, QFontDialog, QInputDialog, QMenu, QTreeWidgetItem, QDialog
 )
@@ -200,6 +200,26 @@
             self.__styleOneItem(itm, style, substyle)
             itm = self.styleElementList.itemBelow(itm)
     
+    def __styleSample(self, color, paper, font=None):
+        """
+        Private method to style the sample text.
+        
+        @param color foreground color for the sample
+        @type QColor
+        @param paper background color for the sample
+        @type QColor
+        @param font font for the sample (defaults to None)
+        @type QFont (optional)
+        """
+        if font:
+            self.sampleText.setFont(font)
+        
+        self.sampleText.setStyleSheet(
+            "QLineEdit {{ color: {0}; background-color: {1}; }}".format(
+                color.name(), paper.name()
+            )
+        )
+    
     @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
     def on_styleElementList_currentItemChanged(self, current, previous):
         """
@@ -219,12 +239,7 @@
         eolfill = self.lexer.eolFill(style, substyle)
         font = self.lexer.font(style, substyle)
         
-        self.sampleText.setFont(font)
-        pl = self.sampleText.palette()
-        pl.setColor(QPalette.ColorRole.Text, colour)
-        pl.setColor(QPalette.ColorRole.Base, paper)
-        self.sampleText.setPalette(pl)
-        self.sampleText.repaint()
+        self.__styleSample(colour, paper, font=font)
         self.eolfillCheckBox.setChecked(eolfill)
         
         selectedOne = len(self.styleElementList.selectedItems()) == 1
@@ -245,10 +260,8 @@
         style, substyle = self.__currentStyles()
         colour = QColorDialog.getColor(self.lexer.color(style, substyle))
         if colour.isValid():
-            pl = self.sampleText.palette()
-            pl.setColor(QPalette.ColorRole.Text, colour)
-            self.sampleText.setPalette(pl)
-            self.sampleText.repaint()
+            paper = self.lexer.paper(style, substyle)
+            self.__styleSample(colour, paper)
             for selItem in self.styleElementList.selectedItems():
                 style, substyle = self.__stylesForItem(selItem)
                 self.lexer.setColor(colour, style, substyle)
@@ -261,12 +274,10 @@
         style and lexer.
         """
         style, substyle = self.__currentStyles()
-        colour = QColorDialog.getColor(self.lexer.paper(style, substyle))
-        if colour.isValid():
-            pl = self.sampleText.palette()
-            pl.setColor(QPalette.ColorRole.Base, colour)
-            self.sampleText.setPalette(pl)
-            self.sampleText.repaint()
+        paper = QColorDialog.getColor(self.lexer.paper(style, substyle))
+        if paper.isValid():
+            colour = self.lexer.color(style, substyle)
+            self.__styleSample(colour, paper)
             for selItem in self.styleElementList.selectedItems():
                 style, substyle = self.__stylesForItem(selItem)
                 self.lexer.setPaper(colour, style, substyle)
@@ -281,10 +292,8 @@
         style, substyle = self.__currentStyles()
         colour = QColorDialog.getColor(self.lexer.paper(style, substyle))
         if colour.isValid():
-            pl = self.sampleText.palette()
-            pl.setColor(QPalette.ColorRole.Base, colour)
-            self.sampleText.setPalette(pl)
-            self.sampleText.repaint()
+            paper = self.lexer.paper(style, substyle)
+            self.__styleSample(colour, paper)
             
             itm = self.styleElementList.topLevelItem(0)
             while itm is not None:

eric ide

mercurial