Repository: spyder-ide/spyder

Issue:
Appearance preferences for syntax highlighting with dark theme look weird
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice

## Problem Description

![image](https://user-images.githubusercontent.com/10170372/57803564-ba536180-7726-11e9-8afc-bb7423c450e4.png)

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 
* Python version: 
* Qt version: 
* PyQt version: 
* Operating System name/version: 


Discussion:
I know how to fix this one.
@goanpeca could you explain a little bit more what is it that looks weird.

I can work on this one if you are interested.
The background of the editor should look all brownish not dark blue on some parts and brownish on others. (the fix for this is probably already found on the code editor?

This should probably be fixed within the code editor widget so that using it elsewhere (like on the preferences) results in the expected look, otherwise we might need to fix it everywhere we use it, which does not sound right.
Thanks @goanpeca. I'm going to fix it. I know why it is doing this.

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/base.py b/spyder/plugins/editor/widgets/base.py
--- a/spyder/plugins/editor/widgets/base.py
+++ b/spyder/plugins/editor/widgets/base.py
@@ -435,21 +435,18 @@ def set_palette(self, background, foreground):
         Set text editor palette colors:
         background color and caret (text cursor) color
         """
-        palette = QPalette()
-        palette.setColor(QPalette.Base, background)
-        palette.setColor(QPalette.Text, foreground)
-        self.setPalette(palette)
-
-        # Set the right background color when changing color schemes
-        # or creating new Editor windows. This seems to be a Qt bug.
-        # Fixes Issue 2028 and 8069
-        if self.objectName():
-            style = "QPlainTextEdit#%s {background: %s; color: %s;}" % \
-                    (self.objectName(), background.name(), foreground.name())
-            self.setStyleSheet(style)
-
-
-    #------Extra selections
+        # Because QtStylsheet overrides QPalette and because some style do not
+        # use the palette for all drawing (e.g. macOS styles), the background
+        # and foreground color of each TextEditBaseWidget instance must be set
+        # with a stylesheet extended with an ID Selector.
+        # Fixes Issue 2028, 8069 and 9248.
+        if not self.objectName():
+            self.setObjectName(self.__class__.__name__ + str(id(self)))
+        style = "QPlainTextEdit#%s {background: %s; color: %s;}" % \
+                (self.objectName(), background.name(), foreground.name())
+        self.setStyleSheet(style)
+
+    # ---- Extra selections
     def get_extra_selections(self, key):
         """Return editor extra selections.
 
diff --git a/spyder/plugins/editor/widgets/codeeditor.py b/spyder/plugins/editor/widgets/codeeditor.py
--- a/spyder/plugins/editor/widgets/codeeditor.py
+++ b/spyder/plugins/editor/widgets/codeeditor.py
@@ -289,22 +289,6 @@ def __init__(self, parent=None):
 
         self.setFocusPolicy(Qt.StrongFocus)
 
-        # We use these object names to set the right background
-        # color when changing color schemes or creating new
-        # Editor windows. This seems to be a Qt bug.
-        # Fixes issues 2028 and 8069
-        plugin_name = repr(parent)
-        if 'editor' in plugin_name.lower():
-            self.setObjectName('editor')
-        elif 'help' in plugin_name.lower():
-            self.setObjectName('help')
-        elif 'historylog' in plugin_name.lower():
-            self.setObjectName('historylog')
-        elif 'configdialog' in plugin_name.lower():
-            self.setObjectName('configdialog')
-        elif 'errordialog' in plugin_name.lower():
-            self.setObjectName('errordialog')
-
         # Caret (text cursor)
         self.setCursorWidth( CONF.get('main', 'cursor/width') )
 


Test patch: