StylingGuide
π¨ Styling Guideβ
This guide explains how to customize the visual appearance of your PyQt/PySide app using the built-in theming engine powered by QCustomTheme, QSS (Qt Style Sheets), and dynamic SCSS variables.
π§± Overviewβ
Styling in your Custom Widgets framework is:
- Modular (
.scssbased) - Theme-aware (
_variables.scss) - Auto-compiled (
main.scssβ.qss) - Designer and developer-friendly
π Styling Structureβ
Your project uses the following style-related files:
/Qss/
βββ scss/
β βββ _variables.scss # Auto-generated theme variables (DO NOT EDIT)
β βββ _styles.scss # Core widget styling (read-only)
β βββ defaultStyle.scss # π§ Your app's custom overrides
β βββ main.scss # SCSS entry point
βββ icons/ # Auto-generated icons for each theme color
βββ fonts/ # Optional custom fonts (e.g., Rosario)
π How It Worksβ
- A theme is selected via
QSettingsor a widget likeQCustomThemeList. - The app reads variables from your JSON theme definition (colors, radius, etc.).
- These are written to
_variables.scss. main.scsscompiles to a.qssfile usingqtsass.- Styles are applied to the running app.
π§© Theme Variables (_variables.scss)β
Variables like the following are auto-injected based on your JSON CustomTheme:
$COLOR_BACKGROUND_1: #16191d;
$COLOR_TEXT_1: #ffffff;
$COLOR_ACCENT_1: #03C3C3;
$CARD_RADIUS: 12px;
$FOOTER_BG: #0f0f0f;
β Do not manually edit
_variables.scss. Instead, define new variables in your theme JSON under"Other-variables".
βοΈ defaultStyle.scss β Your Playgroundβ
This is the file where you write your own styles.
// Sample override
QFrame#card {
background-color: $COLOR_BACKGROUND_2;
border-radius: $CARD_RADIUS;
}
π‘ You can reference any variable from _variables.scss in here.
β Styling Best Practicesβ
| Goal | Do this... |
|---|---|
| Change base background color | Update Background-color in your JSON theme |
| Add a border radius | Use $CARD_RADIUS in defaultStyle.scss |
| Make widget styles consistent | Use SCSS variables instead of hardcoded HEX or px |
| Test a new theme quickly | Modify the theme in JSON and relaunch or call update manually |
| Prevent re-styling | Use objectName (e.g., QPushButton#myBtn) for specificity |
π§ͺ Live Testing Tipsβ
You can force recompile and apply styles manually:
from Custom_Widgets.QCustomTheme import QCustomTheme
theme = QCustomTheme()
theme.applyCompiledSass()
Or refresh styles with:
from Custom_Widgets.QAppSettings import QAppSettings
QAppSettings.updateAppSettings(self)
π§ Icon Styling (Optional)β
Icons are automatically recolored using the themeβs Icons-color or Accent-color.
You can override them in your QSS using styles like:
QPushButton#refreshBtn {
qproperty-icon: url(':/icons/03C3C3/refresh.png');
}
π¬ Need More?β
Refer to the following: