Removes hardcoded background colours and standardized it across the code base#3862
Removes hardcoded background colours and standardized it across the code base#3862jellybean2004 wants to merge 6 commits intomainfrom
Conversation
*Adds BackgroundColor.py *QLineEdit bg change to use these UI constants where it is a simple change
There was a problem hiding this comment.
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.pymodule 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) |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
| self.ui.editMolecularFormula.setStyleSheet(BG_ERROR) | |
| self.ui.editMolecularFormula.setStyleSheet(BG_WARNING) |
| return | ||
| if not density and '@' not in formula: | ||
| self.ui.editMassDensity.setStyleSheet("background-color: yellow") | ||
| self.ui.editMassDensity.setStyleSheet(BG_ERROR) |
There was a problem hiding this comment.
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.
| self.ui.editMassDensity.setStyleSheet(BG_ERROR) | |
| self.ui.editMassDensity.setStyleSheet(BG_WARNING) |
src/sas/qtgui/Utilities/ModelEditors/ReparamEditor/ReparameterizationEditor.py
Show resolved
Hide resolved
| """ | ||
| # Notify the user that fitting is available | ||
| self.cmdFit.setStyleSheet('QPushButton {color: black;}') | ||
| self.cmdFit.setStyleSheet(BG_DEFAULT) |
There was a problem hiding this comment.
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.
| self.cmdFit.setStyleSheet(BG_DEFAULT) | |
| self.cmdFit.setStyleSheet("color: black;") |
src/sas/qtgui/Utilities/GuiUtils.py
Outdated
| def validate(self, input, pos): | ||
|
|
||
| self._setStyleSheet("") | ||
| self._setStyleSheet(f"QLineEdit {{ {BG_DEFAULT} }}") |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
It was previously noted that |
Hi Stuart! |
c9519b4 to
3807514
Compare
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
Installers
Licensing