Skip to content

Removes hardcoded background colours and standardized it across the code base#3862

Open
jellybean2004 wants to merge 6 commits intomainfrom
fix_bg_color
Open

Removes hardcoded background colours and standardized it across the code base#3862
jellybean2004 wants to merge 6 commits intomainfrom
fix_bg_color

Conversation

@jellybean2004
Copy link
Member

Description

This change removes hard-coded background colours from the Qt GUI and centralises them in sas.qtgui.Utilities.BackgroundColor. Widgets now reset to the default Qt theme instead of forcing light backgrounds.

Also, standardised errors/warnings to set the widget background to the respective colours instead of changing the text/border colour.

This is strictly a UI change; functionality should not be affected.

Fixes #3838

How Has This Been Tested?

Manually ran software and inspected changes.

Review Checklist:

Documentation

  • There is nothing that needs documenting
  • Documentation changes are in this PR
  • There is an issue open for the documentation (link?)

Installers

  • There is a chance this will affect the installers, if so
    • Windows installer (GH artifact) has been tested (installed and worked)
    • MacOSX installer (GH artifact) has been tested (installed and worked)
    • Wheels installer (GH artifact) has been tested (installed and worked)

Licensing

  • The introduced changes comply with SasView license (BSD 3-Clause)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #3838 by removing hardcoded background colors that break Dark Mode support and centralizing color management in a new BackgroundColor.py module. The changes aim to make the Qt GUI respect system themes instead of forcing light backgrounds.

Changes:

  • Created centralized BackgroundColor.py module with constants BG_DEFAULT (""), BG_ERROR, and BG_WARNING
  • Replaced hardcoded background color strings across 18 files with the new constants
  • Removed local color constant definitions in favor of the centralized module

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
src/sas/qtgui/Utilities/BackgroundColor.py New module defining centralized color constants for theming
src/sas/qtgui/Utilities/Preferences/PreferencesWidget.py Updated to use BG_DEFAULT and BG_WARNING for input validation styling
src/sas/qtgui/Utilities/Preferences/PlottingPreferencesWidget.py Updated to use BG_DEFAULT for field reset
src/sas/qtgui/Utilities/Preferences/DisplayPreferencesWidget.py Updated to use BG_DEFAULT for field reset
src/sas/qtgui/Utilities/ModelEditors/TabbedEditor/TabbedModelEditor.py Updated to use BG_DEFAULT and BG_ERROR for editor styling
src/sas/qtgui/Utilities/ModelEditors/ReparamEditor/ReparameterizationEditor.py Updated to use BG_DEFAULT and BG_ERROR for editor styling
src/sas/qtgui/Utilities/ModelEditors/AddMultEditor/AddMultEditor.py Removed local color constants, updated to use centralized BG_DEFAULT and BG_ERROR
src/sas/qtgui/Utilities/GuiUtils.py Updated FormulaValidator to use BG_DEFAULT and BG_WARNING
src/sas/qtgui/Perspectives/Invariant/InvariantPerspective.py Removed local color constants, updated to use centralized BG_DEFAULT and BG_ERROR
src/sas/qtgui/Perspectives/Fitting/MultiConstraint.py Updated constraint validation to use BG_DEFAULT and BG_ERROR
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py Updated button styling to use BG_DEFAULT and BG_ERROR
src/sas/qtgui/Perspectives/Fitting/FittingOptions.py Updated validation styling to use BG_DEFAULT and BG_WARNING
src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py Updated button styling to use BG_DEFAULT and BG_ERROR
src/sas/qtgui/Perspectives/Fitting/ComplexConstraint.py Updated constraint validation to use BG_DEFAULT and BG_ERROR
src/sas/qtgui/Perspectives/Corfunc/CorfuncPerspective.py Removed local color constants, updated to use centralized BG_DEFAULT and BG_ERROR
src/sas/qtgui/Calculators/SldPanel.py Updated validation styling to use BG_DEFAULT, BG_ERROR, and BG_WARNING
src/sas/qtgui/Calculators/ResolutionCalculatorPanel.py Removed local color constants, updated to use centralized BG_DEFAULT and BG_ERROR
src/sas/qtgui/Calculators/GenericScatteringCalculator.py Removed local color constants, updated to use centralized BG_DEFAULT, BG_ERROR, and BG_WARNING
src/sas/qtgui/Calculators/DataOperationUtilityPanel.py Removed local color constants, updated to use centralized BG_DEFAULT and BG_ERROR

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

results = neutronSldAlgorithm(str(formula), density, float(neutronWavelength))
except (ValueError, ParseException, AssertionError, KeyError):
self.ui.editMolecularFormula.setStyleSheet("background-color: yellow")
self.ui.editMolecularFormula.setStyleSheet(BG_ERROR)
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code used "background-color: yellow" for this validation error, which is a warning-level color. However, this has been changed to BG_ERROR which is a more severe red/pink color. Based on the context (invalid molecular formula), this seems like it should use BG_WARNING instead of BG_ERROR to maintain the same visual severity level as before.

Copilot uses AI. Check for mistakes.
results = xraySldAlgorithm(str(formula), density, float(xrayWavelength))
except (ValueError, ParseException, AssertionError, KeyError):
self.ui.editMolecularFormula.setStyleSheet("background-color: yellow")
self.ui.editMolecularFormula.setStyleSheet(BG_ERROR)
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code used "background-color: yellow" for this validation error, which is a warning-level color. However, this has been changed to BG_ERROR which is a more severe red/pink color. Based on the context (invalid molecular formula), this seems like it should use BG_WARNING instead of BG_ERROR to maintain the same visual severity level as before.

Suggested change
self.ui.editMolecularFormula.setStyleSheet(BG_ERROR)
self.ui.editMolecularFormula.setStyleSheet(BG_WARNING)

Copilot uses AI. Check for mistakes.
return
if not density and '@' not in formula:
self.ui.editMassDensity.setStyleSheet("background-color: yellow")
self.ui.editMassDensity.setStyleSheet(BG_ERROR)
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code used "background-color: yellow" for this validation error, which is a warning-level color. However, this has been changed to BG_ERROR which is a more severe red/pink color. Based on the context (missing density field), this seems like it should use BG_WARNING instead of BG_ERROR to maintain the same visual severity level as before.

Suggested change
self.ui.editMassDensity.setStyleSheet(BG_ERROR)
self.ui.editMassDensity.setStyleSheet(BG_WARNING)

Copilot uses AI. Check for mistakes.
"""
# Notify the user that fitting is available
self.cmdFit.setStyleSheet('QPushButton {color: black;}')
self.cmdFit.setStyleSheet(BG_DEFAULT)
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code set the text color (color: black), but BG_DEFAULT is designed for background colors. Using an empty string here will clear all styles, which may not preserve the intended behavior. Consider creating separate constants for text color styling, or explicitly set the text color here.

Suggested change
self.cmdFit.setStyleSheet(BG_DEFAULT)
self.cmdFit.setStyleSheet("color: black;")

Copilot uses AI. Check for mistakes.
def validate(self, input, pos):

self._setStyleSheet("")
self._setStyleSheet(f"QLineEdit {{ {BG_DEFAULT} }}")

This comment was marked as outdated.

@llimeht
Copy link
Contributor

llimeht commented Feb 7, 2026

It was previously noted that src/sas/qtgui/Utilities/About/Credits.py didn't seem to obey the CSS setting for dark mode (even though that is in the html file src/sas/system/credits.html (generated by build_tools/compile_licenses.py) and that file renders fine in a standalone browser. Is this related and a similar fix?

@jellybean2004
Copy link
Member Author

It was previously noted that src/sas/qtgui/Utilities/About/Credits.py didn't seem to obey the CSS setting for dark mode (even though that is in the html file src/sas/system/credits.html (generated by build_tools/compile_licenses.py) and that file renders fine in a standalone browser. Is this related and a similar fix?

Hi Stuart!
I found that the problem lies in the QTextBrowser not supporting media queries, so it is a different issue.
I have pushed a commit adding a short snippet to credits.py to identify and use the dark theme. Could you kindly review it? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hard-coded background color breaks Dark Mode support

2 participants