qdarktheme#
qdarktheme is a python module to apply original theme to PySide and PyQt.
- qdarktheme.setup_theme(theme: str = 'dark', corner_shape: str = 'rounded', custom_colors: Optional[dict[str, str | dict[str, str]]] = None, additional_qss: Optional[str] = None, *, default_theme: str = 'dark') None[source]#
Apply the theme which looks like flat design to the Qt App completely.
This function doesn’t only set the Qt stylesheet, it applies the complete style to your Qt application using QPalette etc. Also if theme is
auto, try to listen to changes to the OS’s theme and switch to a matching theme accordingly.- Parameters
theme – The theme name. There are dark, light and auto. If
auto, try to sync with system theme. If failed to detect system theme, use the theme set in argumentdefault_theme.corner_shape – The corner shape. There are rounded and sharp shape.
custom_colors – The custom color map. Overrides the default color for color id you set. Also you can customize a specific theme only. See example 5.
additional_qss – Additional stylesheet text. You can add your original stylesheet text.
default_theme – The default theme name. The theme set by this argument will be used when system theme detection fails.
- Raises
ValueError – If the argument is wrong.
KeyError – If the color id of custom_colors is wrong.
- Returns
The stylesheet string for the given arguments.
Examples
Set stylesheet to your Qt application.
Setup style and sync to system theme
app = QApplication([]) qdarktheme.setup_theme()
Use Dark Theme
app = QApplication([]) qdarktheme.setup_theme("dark")
Sharp corner
# Change corner shape to sharp. app = QApplication([]) qdarktheme.setup_theme(corner_shape="sharp")
Customize color
app = QApplication([]) qdarktheme.setup_theme(custom_colors={"primary": "#D0BCFF"})
Customize a specific theme only
app = QApplication([]) qdarktheme.setup_theme( theme="auto", custom_colors={ "[dark]": { "primary": "#D0BCFF", } }, )
- qdarktheme.enable_hi_dpi() None[source]#
Allow to HiDPI.
This function must be set before instantiation of QApplication.. For Qt6 bindings, HiDPI “just works” without using this function.
- qdarktheme.load_stylesheet(theme: str = 'dark', corner_shape: str = 'rounded', custom_colors: Optional[dict[str, str | dict[str, str]]] = None, *, default_theme: str = 'dark', border: Optional[str] = None) str[source]#
Load the style sheet which looks like flat design. There are dark and light theme.
- Parameters
theme – The theme name. There are dark, light and auto. If
auto, try to detect system theme. If failed to detect system theme, use the theme set in argumentdefault_theme.corner_shape – The corner shape. There are rounded and sharp shape.
custom_colors – The custom color map. Overrides the default color for color id you set. Also you can customize a specific theme only. See example 6.
default_theme – The default theme name. The theme set by this argument will be used when system theme detection fails.
border – The corner shape. There are rounded and sharp shape. This argument is deprecated since v1.2.0. Please use corner_shape instead. This argument override value of argument corner_shape.
- Raises
ValueError – If the arguments of this method is wrong.
KeyError – If the color id of custom_colors is wrong.
- Returns
The stylesheet string for the given arguments.
Examples
Set stylesheet to your Qt application.
Dark Theme
app = QApplication([]) app.setStyleSheet(qdarktheme.load_stylesheet()) # or app.setStyleSheet(qdarktheme.load_stylesheet("dark"))
Light Theme
app = QApplication([]) app.setStyleSheet(qdarktheme.load_stylesheet("light"))
Automatic detection of system theme
app = QApplication([]) app.setStyleSheet(qdarktheme.load_stylesheet("auto"))
Sharp corner
# Change corner shape to sharp. app = QApplication([]) app.setStyleSheet(qdarktheme.load_stylesheet(corner_shape="sharp"))
Customize color
app = QApplication([]) app.setStyleSheet(qdarktheme.load_stylesheet(custom_colors={"primary": "#D0BCFF"}))
Customize a specific theme only
app = QApplication([]) app.setStyleSheet( qdarktheme.load_stylesheet( theme="auto", custom_colors={ "[dark]": { "primary": "#D0BCFF", } }, ) )
- qdarktheme.load_palette(theme: str = 'dark', custom_colors: Optional[dict[str, str | dict[str, str]]] = None, *, default_theme: str = 'dark', for_stylesheet: bool = False)[source]#
Load the QPalette for the dark or light theme.
- Parameters
theme – The theme name. There are dark, light and auto. If
auto, try to detect system theme. If failed to detect system theme, use the theme set in argumentdefault_theme.custom_colors – The custom color map. Overrides the default color for color id you set. Also you can customize a specific theme only. See example 5.
default_theme – The default theme name. The theme set by this argument will be used when system theme detection fails.
for_stylesheet – If True, only includes colors that cannot be set in stylesheets, such as
linkandplaceholder.
- Raises
TypeError – If the arg name of theme is wrong.
KeyError – If the color id of custom_colors is wrong.
- Returns
The QPalette for the given theme.
- Return type
QPalette
Examples
Set QPalette to your Qt application.
Dark Theme
app = QApplication([]) app.setPalette(qdarktheme.load_palette()) # or app.setPalette(qdarktheme.load_palette("dark"))
Light Theme
app = QApplication([]) app.setPalette(qdarktheme.load_palette("light"))
Automatic detection of system theme
app = QApplication([]) app.setPalette(qdarktheme.load_palette("auto"))
Customize color
app = QApplication([]) app.setPalette(custom_colors={"primary": "#D0BCFF"})
Customize a specific theme only
app = QApplication([]) app.setStyleSheet( qdarktheme.load_stylesheet( theme="auto", custom_colors={ "[dark]": { "primary": "#D0BCFF", } }, ) )