code: def set_palette(self, background, foreground):
          
          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)
docs: Set text editor palette colors:
          background color and caret (text cursor) color