Foundations
Themes and colors
Switch the application theme and read theme colors for custom painting.
Switch the theme
FluentElement::setTheme() switches the application between Light, Dark, and HighContrast, and existing Fluent controls repaint. To change tokens on one element only, pass a JSON object to setThemeOverrides(). Overrides survive theme changes and do not apply to child widgets.
#include <FluentQt/Foundation.h>
fluent::FluentElement::setTheme(fluent::FluentElement::Dark);import fluentqt
fluentqt.set_theme(fluentqt.Theme.Dark)Use theme colors
Read colors by role, such as textPrimary or bgCanvas, instead of hard-coding RGB values, so custom painting follows the theme. In C++ paint code, use themeColorsRef(); in Python, subclass fluentqt.FluentWidget and use theme_tokens().
#include <FluentQt/Foundation.h>
// Inside a FluentElement-based widget's paintEvent()
const auto& colors = themeColorsRef();
const QColor background = colors.bgCanvas;
const QColor text = colors.textPrimary;import fluentqt
class Swatch(fluentqt.FluentWidget):
def paintEvent(self, event):
colors = self.theme_tokens().colors
background = colors.bgCanvas
text = colors.textPrimary