### Run Example App Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/installation_guide.md Launch the PyQtDarkTheme example application to explore its features. This command requires the package to be installed. ```default python -m qdarktheme.widget_gallery ``` -------------------------------- ### Install Dependencies and Qt Bindings Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/contributing.md Install project dependencies using Poetry and then install Qt bindings (PySide6) using pip within the virtual environment. ```bash poetry install poetry run pip install PySide6 ``` -------------------------------- ### Apply Dark Theme to Qt Applications Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Basic implementation examples for different Qt bindings. ```python import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Apply dark theme. qdarktheme.setup_theme() main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` ```python import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Apply dark theme. qdarktheme.setup_theme() main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` ```python import sys from PySide2.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme # Enable HiDPI. qdarktheme.enable_hi_dpi() app = QApplication(sys.argv) # Apply dark theme. qdarktheme.setup_theme() main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() app.exec_() ``` ```python import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme # Enable HiDPI. qdarktheme.enable_hi_dpi() app = QApplication(sys.argv) # Apply dark theme. qdarktheme.setup_theme() main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` ```python import pyqtgraph as pg from pyqtgraph.Qt.QtGui import QMainWindow, QPushButton import qdarktheme app = pg.mkQApp() # Apply dark theme. qdarktheme.setup_theme() main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() pg.exec() ``` -------------------------------- ### Setup Theme and Sync to System Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Applies the default dark theme and enables synchronization with the operating system's theme settings. Ensure QApplication is instantiated before calling this. ```python app = QApplication([]) qdarktheme.setup_theme() ``` -------------------------------- ### QPalette template example Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/style/README.md Template syntax for generating dynamic colors in QPalette format. ```plain text {{ background|color(state="popup")|palette }} ``` -------------------------------- ### Setup Theme with Custom Primary Color Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Applies a theme with a customized primary color. Ensure QApplication is instantiated before calling this. ```python app = QApplication([]) qdarktheme.setup_theme(custom_colors={"primary": "#D0BCFF"}) ``` -------------------------------- ### Install PyQtDarkTheme from GitHub Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/installation_guide.md Install the latest version of PyQtDarkTheme directly from its GitHub repository using pip. This is useful for accessing the newest features and bug fixes. ```default pip install git+https://github.com/5yutan5/PyQtDarkTheme.git@main ``` -------------------------------- ### Install PyQtDarkTheme via Pip Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/installation_guide.md Install the PyQtDarkTheme package using pip. Ensure Python 3.7+ and Qt 5.15+ are installed. ```default pip install pyqtdarktheme ``` -------------------------------- ### Basic Dark Theme Setup Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/README.md Apply the complete dark theme to a Qt application using PySide6. Ensure QApplication is instantiated before calling setup_theme. ```Python import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Apply the complete dark theme to your Qt App. qdarktheme.setup_theme() main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` -------------------------------- ### Setup Dark Theme Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Applies the 'dark' theme to the Qt application. Ensure QApplication is instantiated before calling this. ```python app = QApplication([]) qdarktheme.setup_theme("dark") ``` -------------------------------- ### Setup Theme with Sharp Corners Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Applies a theme with sharp corners instead of the default rounded ones. Ensure QApplication is instantiated before calling this. ```python # Change corner shape to sharp. app = QApplication([]) qdarktheme.setup_theme(corner_shape="sharp") ``` -------------------------------- ### Install Pre-commit Hook Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/contributing.md Install the pre-commit hook to automatically check code style before committing changes. ```bash poetry run pre-commit install ``` -------------------------------- ### Theme Setup and Management API Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/index.md Functions for setting up, enabling, and managing dark themes in Qt applications. ```APIDOC ## setup_theme() ### Description Applies a dark theme to the Qt application. ### Method `setup_theme()` ### Endpoint N/A (Function call) ### Parameters None ### Request Example ```python import qdarktheme qdarktheme.setup_theme() ``` ### Response None ## enable_hi_dpi() ### Description Enables High DPI scaling for the theme. ### Method `enable_hi_dpi()` ### Endpoint N/A (Function call) ### Parameters None ### Request Example ```python import qdarktheme qdarktheme.enable_hi_dpi() ``` ### Response None ## stop_sync() ### Description Stops the theme synchronization process. ### Method `stop_sync()` ### Endpoint N/A (Function call) ### Parameters None ### Request Example ```python import qdarktheme qdarktheme.stop_sync() ``` ### Response None ## get_themes() ### Description Retrieves a list of available themes. ### Method `get_themes()` ### Endpoint N/A (Function call) ### Parameters None ### Request Example ```python import qdarktheme available_themes = qdarktheme.get_themes() print(available_themes) ``` ### Response - **themes** (list) - A list of strings, where each string is a theme name. ### Response Example ```json { "themes": ["light", "dark", "blue-dark"] } ``` ## clear_cache() ### Description Clears the theme cache. ### Method `clear_cache()` ### Endpoint N/A (Function call) ### Parameters None ### Request Example ```python import qdarktheme qdarktheme.clear_cache() ``` ### Response None ``` -------------------------------- ### QSS Template examples Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/style/README.md Various template filters used within base.qss for dynamic styling. ```plain text {{ background|color }} ``` ```plain text {{ primary|color(state="selection.background") }} ``` ```plain text {{ primary|color|url(id="east") }} ``` ```plain text {{ foreground|color(state="icon")|url(id="expand_less", rotate=180) }} ``` ```plain text {{ corner-shape|corner(size=2) }} ``` ```plain text {{ |env(value="popupMode=MenuButtonPopup", version="<6.0.0", qt="PySide2") }} ``` -------------------------------- ### Setup Theme with Specific Dark Theme Customization Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Applies the 'auto' theme while customizing the primary color specifically for the dark variant. Ensure QApplication is instantiated before calling this. ```python app = QApplication([]) qdarktheme.setup_theme( theme="auto", custom_colors={ "[dark]": { "primary": "#D0BCFF", } }, ) ``` -------------------------------- ### Run Pytest for Local Development Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/contributing.md Execute the project's tests using pytest to ensure the current setup is passing on your machine. ```bash poetry run pytest tests ``` -------------------------------- ### Get Available Themes Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Retrieves a tuple of all available theme names. This is useful for populating theme selection widgets. ```APIDOC ## get_themes ### Description Returns a tuple of available theme names. Useful for building theme selection UI components. ### Method GET (conceptual) ### Endpoint N/A (Python function) ### Parameters None ### Request Example ```python themes = qdarktheme.get_themes() print(themes) # Output: ('dark', 'light') ``` ### Response #### Success Response (200) - **themes** (tuple) - A tuple containing strings of available theme names. ``` -------------------------------- ### Supported SVG format Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/style/README.md Example of a simple SVG structure supported by the module. Avoid using fill, fill-opacity, or transform properties. ```svg ``` -------------------------------- ### setup_theme Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Applies a complete theme (stylesheet, QPalette, QStyle) to the Qt application. Can automatically sync with OS theme changes. ```APIDOC ## setup_theme ### Description The primary function for applying a complete theme to your Qt application. It sets the stylesheet, QPalette, and QStyle in one call, and can optionally listen for OS theme changes when set to "auto" mode. ### Method `setup_theme()` ### Parameters #### Keyword Arguments - **theme** (str) - Optional - The theme to apply. Options: "dark" (default), "light", "auto". - **corner_shape** (str) - Optional - The shape of widget corners. Options: "rounded" (default), "sharp". - **custom_colors** (dict) - Optional - A dictionary to specify custom accent colors. For "auto" theme, can be a dictionary with keys `"[dark]"` and `"[light]"` to specify different colors for dark and light modes. - **default_theme** (str) - Optional - The fallback theme to use if OS theme detection fails in "auto" mode. Options: "dark", "light". - **additional_qss** (str) - Optional - A string containing additional Qt Stylesheet rules to append to the theme. ### Request Example ```python import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Apply dark theme (default) qdarktheme.setup_theme() # Or apply light theme qdarktheme.setup_theme("light") # Or sync with OS theme automatically qdarktheme.setup_theme("auto") # Customize with sharp corners and custom accent color qdarktheme.setup_theme( theme="dark", corner_shape="sharp", # Options: "rounded" (default), "sharp" custom_colors={"primary": "#D0BCFF"} ) # Theme-specific customizations for auto mode qdarktheme.setup_theme( theme="auto", custom_colors={ "[dark]": {"primary": "#D0BCFF"}, "[light]": {"primary": "#6750A4"} }, default_theme="dark" # Fallback if OS theme detection fails ) # Append additional custom styles additional_qss = """ QPushButton { border-width: 2px; border-style: dashed; } """ qdarktheme.setup_theme(additional_qss=additional_qss) main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` ### Response This function does not return a value. It modifies the application's theme directly. ``` -------------------------------- ### qdarktheme.setup_theme Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Applies a flat design theme to the entire Qt application. ```APIDOC ## setup_theme(theme='dark', corner_shape='rounded', custom_colors=None, additional_qss=None, *, default_theme='dark') ### Description Applies the complete flat design style to your Qt application. If the theme is set to 'auto', it attempts to sync with the OS theme. ### Parameters - **theme** (str) - Optional - The theme name ('dark', 'light', 'auto'). - **corner_shape** (str) - Optional - The corner shape ('rounded', 'sharp'). - **custom_colors** (dict) - Optional - Map to override default colors. - **additional_qss** (str) - Optional - Additional stylesheet text to inject. - **default_theme** (str) - Optional - Theme to use if system detection fails. ### Raises - **ValueError** - If arguments are invalid. - **KeyError** - If color IDs in custom_colors are invalid. ``` -------------------------------- ### Apply Themes with setup_theme Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt The primary function for applying a complete theme, including stylesheet, QPalette, and QStyle. It supports automatic OS theme synchronization and custom styling options. ```python import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Apply dark theme (default) qdarktheme.setup_theme() # Or apply light theme qdarktheme.setup_theme("light") # Or sync with OS theme automatically qdarktheme.setup_theme("auto") # Customize with sharp corners and custom accent color qdarktheme.setup_theme( theme="dark", corner_shape="sharp", # Options: "rounded" (default), "sharp" custom_colors={"primary": "#D0BCFF"} ) # Theme-specific customizations for auto mode qdarktheme.setup_theme( theme="auto", custom_colors={ "[dark]": {"primary": "#D0BCFF"}, "[light]": {"primary": "#6750A4"} }, default_theme="dark" # Fallback if OS theme detection fails ) # Append additional custom styles additional_qss = """ QPushButton { border-width: 2px; border-style: dashed; } """ qdarktheme.setup_theme(additional_qss=additional_qss) main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` -------------------------------- ### Apply Light Theme Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/README.md Apply the light theme to your Qt application by passing 'light' as an argument to setup_theme. ```Python qdarktheme.setup_theme("light") ``` -------------------------------- ### Load QPalette and Stylesheet Separately Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/README.md Load only the QPalette or stylesheet for custom integration. The setup_theme function uses these internally. ```Python palette = qdarktheme.load_palette(theme="dark") stylesheet = qdarktheme.load_stylesheet(theme="dark") ``` -------------------------------- ### Build styles command Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/style/README.md Run this command to apply style changes to the qdarktheme module. ```sh python -m tools.build_styles ``` -------------------------------- ### Check Qt Theme with Widget Gallery Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/contributing.md Launch the built-in widget gallery application to visually check the dark and light themes. ```bash poetry run python -m qdarktheme.widget_gallery ``` -------------------------------- ### Sync with OS Theme Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/README.md Automatically sync the application's theme with the operating system's theme settings by passing 'auto' to setup_theme. ```Python qdarktheme.setup_theme("auto") ``` -------------------------------- ### Apply Stylesheets to Qt Applications Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Methods for applying various theme configurations to a QApplication via stylesheets. ```default app = QApplication([]) app.setStyleSheet(qdarktheme.load_stylesheet()) # or app.setStyleSheet(qdarktheme.load_stylesheet("dark")) ``` ```default app = QApplication([]) app.setStyleSheet(qdarktheme.load_stylesheet("light")) ``` ```default app = QApplication([]) app.setStyleSheet(qdarktheme.load_stylesheet("auto")) ``` ```default # Change corner shape to sharp. app = QApplication([]) app.setStyleSheet(qdarktheme.load_stylesheet(corner_shape="sharp")) ``` ```default app = QApplication([]) app.setStyleSheet(qdarktheme.load_stylesheet(custom_colors={"primary": "#D0BCFF"})) ``` ```default app = QApplication([]) app.setStyleSheet( qdarktheme.load_stylesheet( theme="auto", custom_colors={ "[dark]": { "primary": "#D0BCFF", } }, ) ) ``` -------------------------------- ### Apply stylesheet to Qt application Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Use load_stylesheet to retrieve the theme's QSS and apply it globally to the application. ```Python qdarktheme.load_stylesheet() ``` ```default import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Apply stylesheet as "dark" theme app.setStyleSheet(qdarktheme.load_stylesheet()) main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` -------------------------------- ### Enable HiDPI Support Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/README.md Enable HiDPI support by calling enable_hi_dpi() before QApplication instantiation. Note that for Qt6 bindings, HiDPI support is automatic. ```Python # enable_hi_dpi() must be called before the instantiation of QApplication. qdarktheme.enable_hi_dpi() app = QApplication(sys.argv) qdarktheme.setup_theme() ``` -------------------------------- ### Apply Palettes to Qt Applications Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Methods for applying theme-based QPalettes to a QApplication. ```default app = QApplication([]) app.setPalette(qdarktheme.load_palette()) # or app.setPalette(qdarktheme.load_palette("dark")) ``` ```default app = QApplication([]) app.setPalette(qdarktheme.load_palette("light")) ``` ```default app = QApplication([]) app.setPalette(qdarktheme.load_palette("auto")) ``` ```default app = QApplication([]) app.setPalette(custom_colors={"primary": "#D0BCFF"}) ``` ```default app = QApplication([]) app.setStyleSheet( qdarktheme.load_stylesheet( theme="auto", custom_colors={ "[dark]": { "primary": "#D0BCFF", } }, ) ) ``` -------------------------------- ### Retrieve available themes with get_themes Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Use this to populate UI components like dropdowns with supported theme names. ```python import sys from PyQt6.QtWidgets import QApplication, QComboBox, QHBoxLayout, QMainWindow, QWidget import qdarktheme app = QApplication(sys.argv) qdarktheme.setup_theme("dark") main_win = QMainWindow() # Create theme selector dropdown combo_box = QComboBox() themes = qdarktheme.get_themes() # Returns ("dark", "light") combo_box.addItems(themes) # Connect to theme switcher combo_box.currentTextChanged.connect(qdarktheme.setup_theme) layout = QHBoxLayout() layout.addWidget(combo_box) central_widget = QWidget() central_widget.setLayout(layout) main_win.setCentralWidget(central_widget) main_win.show() app.exec() ``` -------------------------------- ### Apply QPalette to Qt application Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Use load_palette to retrieve a theme-specific QPalette and apply it to the application. ```Python qdarktheme.load_palette() ``` ```default import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) # Apply dark theme app.setPalette(qdarktheme.load_palette()) main_win.show() app.exec() ``` ```Python import qdarktheme dark_palette = qdarktheme.load_palette() link_color = dark_palette.link().color() link_rgb = link_color.getRgb() ``` -------------------------------- ### Enable HiDPI Scaling Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Call enable_hi_dpi before QApplication instantiation. Note that Qt6 bindings handle this automatically. ```python # enable_hi_dpi() must be called before instantiation of QApplication. qdarktheme.enable_hi_dpi() app = QApplication(sys.argv) ``` -------------------------------- ### Clone PyQtDarkTheme Repository Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/contributing.md Clone the repository using git and navigate into the project directory. ```bash git@github.com:5yutan5/PyQtDarkTheme.git cd PyQtDarkTheme ``` -------------------------------- ### Utility Functions Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Additional utility functions for managing HiDPI and system theme synchronization. ```APIDOC ## enable_hi_dpi() ### Description Enables HiDPI support. Must be called before the instantiation of QApplication. ## stop_sync() ### Description Stops the automatic synchronization with the system theme. ``` -------------------------------- ### Enable HiDPI Scaling with enable_hi_dpi Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Enables HiDPI scaling for Qt5 bindings. This must be invoked prior to the instantiation of QApplication. ```python import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme # MUST be called before QApplication instantiation qdarktheme.enable_hi_dpi() app = QApplication(sys.argv) qdarktheme.setup_theme() main_win = QMainWindow() push_button = QPushButton("HiDPI Enabled!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` -------------------------------- ### Manual Theme Switching Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Switch themes manually using a QComboBox. ```python combo_box = QComboBox() combo_box.addItems(qdarktheme.get_themes()) combo_box.currentTextChanged.connect(qdarktheme.setup_theme) ``` ```python import sys from PyQt6.QtWidgets import QApplication, QComboBox, QHBoxLayout, QMainWindow, QWidget import qdarktheme app = QApplication(sys.argv) qdarktheme.setup_theme("dark") main_win = QMainWindow() combo_box = QComboBox() combo_box.addItems(qdarktheme.get_themes()) combo_box.currentTextChanged.connect(qdarktheme.setup_theme) layout = QHBoxLayout() layout.addWidget(combo_box) central_widget = QWidget() central_widget.setLayout(layout) main_win.setCentralWidget(central_widget) main_win.show() app.exec() ``` -------------------------------- ### Configure Palettes with load_palette Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Returns a QPalette configured for the specified theme. This allows for direct access to theme colors or palette-only styling. ```python import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Get dark theme palette palette = qdarktheme.load_palette() app.setPalette(palette) # Get light theme palette palette = qdarktheme.load_palette("light") # Auto-detect system theme palette = qdarktheme.load_palette("auto") # Custom colors palette = qdarktheme.load_palette( theme="dark", custom_colors={"primary": "#D0BCFF"} ) # Access theme colors programmatically dark_palette = qdarktheme.load_palette("dark") link_color = dark_palette.link().color() link_rgb = link_color.getRgb() # Returns (R, G, B, A) tuple print(f"Link color RGB: {link_rgb}") main_win = QMainWindow() push_button = QPushButton("Palette Applied!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` -------------------------------- ### enable_hi_dpi Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Enables HiDPI scaling support for Qt5 applications. Must be called before QApplication instantiation. ```APIDOC ## enable_hi_dpi ### Description Enables HiDPI scaling support for Qt5 bindings (PyQt5, PySide2). Must be called before QApplication instantiation. Qt6 bindings handle HiDPI automatically. ### Method `enable_hi_dpi()` ### Parameters This function does not accept any parameters. ### Request Example ```python import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme # MUST be called before QApplication instantiation qdarktheme.enable_hi_dpi() app = QApplication(sys.argv) qdarktheme.setup_theme() main_win = QMainWindow() push_button = QPushButton("HiDPI Enabled!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` ### Response This function does not return a value. It modifies the application's scaling behavior. ``` -------------------------------- ### Utility Methods Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Helper methods for retrieving available themes and managing library caches. ```APIDOC ## qdarktheme.get_themes ### Description Returns a tuple of all available theme names. ### Response - **themes** (tuple[str, ...]) - List of available theme names. ## qdarktheme.clear_cache ### Description Clears the resource caches stored in the system home path. ``` -------------------------------- ### qdarktheme.load_stylesheet Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Generates and returns the stylesheet string for a given theme configuration without applying it directly to the application. ```APIDOC ## load_stylesheet(theme='dark', corner_shape='rounded', custom_colors=None, *, default_theme='dark') ### Description Loads and returns the stylesheet string for the specified theme configuration. ### Parameters - **theme** (str) - Optional - The theme name ('dark', 'light', 'auto'). - **corner_shape** (str) - Optional - The corner shape ('rounded', 'sharp'). - **custom_colors** (dict) - Optional - Map to override default colors. - **default_theme** (str) - Optional - Theme to use if system detection fails. ### Returns - **str** - The generated stylesheet string. ``` -------------------------------- ### Using Standard Icons Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Demonstrates how PyQtDarkTheme overrides Qt's standard icons with modern Material Design icons that automatically adjust their color based on the current theme. ```APIDOC ## Using Standard Icons ### Description When using `setup_theme()`, PyQtDarkTheme overrides Qt's standard icons with modern Material Design icons that automatically adjust their color based on the current theme. ### Method GET (conceptual, for retrieving icons) ### Endpoint N/A (Python code) ### Parameters None ### Request Example ```python # Get themed standard icons style = main_win.style() save_icon = style.standardIcon(QStyle.StandardPixmap.SP_DialogSaveButton) # Create toolbar with themed icons toolbar = QToolBar() toolbar.addAction(save_icon, "Save") ``` ### Response #### Success Response (200) - **Icons** (QIcon) - Themed standard icons that adapt to the current theme. ``` -------------------------------- ### Use overridden Qt standard icons Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Access theme-aware icons via QStyle.standardIcon after initializing the theme. ```Python save_pixmap = QStyle.StandardPixmap.SP_DialogSaveButton save_icon = win.style().standardIcon(save_pixmap) push_button = QPushButton("Save") push_button.setIcon(save_icon) ``` ```default import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QStyle import qdarktheme app = QApplication(sys.argv) qdarktheme.setup_theme() main_win = QMainWindow() save_pixmap = QStyle.StandardPixmap.SP_DialogSaveButton save_icon = main_win.style().standardIcon(save_pixmap) push_button = QPushButton("Save") push_button.setIcon(save_icon) main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` -------------------------------- ### Load Stylesheet Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Loads a stylesheet string for the Qt application. This function does not apply the theme directly but returns the stylesheet to be applied manually. Supports 'dark', 'light', and 'auto' themes. ```python stylesheet = qdarktheme.load_stylesheet(theme="dark") ``` -------------------------------- ### qdarktheme.load_stylesheet Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Loads a stylesheet for the Qt application based on the specified theme and customization options. ```APIDOC ## qdarktheme.load_stylesheet ### Description Loads the stylesheet for the dark or light theme to be applied to a Qt application. ### Parameters - **theme** (str) - Optional - The theme name ('dark', 'light', or 'auto'). Defaults to 'dark'. - **corner_shape** (str) - Optional - Defines the corner shape (e.g., 'sharp'). - **custom_colors** (dict) - Optional - A map of custom colors to override defaults. ### Request Example ```python app.setStyleSheet(qdarktheme.load_stylesheet(theme="auto", custom_colors={"primary": "#D0BCFF"})) ``` ``` -------------------------------- ### Enable HiDPI Support Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Enables High Dots Per Inch (HiDPI) support for the Qt application. This function must be called before instantiating QApplication. ```python qdarktheme.enable_hi_dpi() ``` -------------------------------- ### qdarktheme.load_palette Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Loads the QPalette for the specified theme, allowing for fine-grained color control in Qt applications. ```APIDOC ## qdarktheme.load_palette ### Description Loads the QPalette for the dark or light theme. Useful for setting application-wide color palettes. ### Parameters - **theme** (str) - Optional - The theme name ('dark', 'light', or 'auto'). - **custom_colors** (dict) - Optional - Custom color map to override default colors. - **default_theme** (str) - Optional - Theme to use if system detection fails. - **for_stylesheet** (bool) - Optional - If True, only includes colors not set in stylesheets. ### Response - **QPalette** (QPalette) - The palette object for the given theme. ``` -------------------------------- ### Toggle Dark/Light Theme Automatically Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Use the 'auto' argument to sync with the OS theme. ```python qdarktheme.setup_theme("auto") ``` ```python import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) qdarktheme.setup_theme("auto") main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` -------------------------------- ### Clear resource caches with clear_cache Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Use this to remove cached theme resources from the system home path for troubleshooting. ```python import qdarktheme # Clear all cached theme resources qdarktheme.clear_cache() ``` -------------------------------- ### Use themed standard icons Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt PyQtDarkTheme automatically overrides standard Qt icons with Material Design versions that adapt to the current theme. ```python import sys from PySide6.QtWidgets import ( QApplication, QMainWindow, QPushButton, QStyle, QVBoxLayout, QWidget, QToolBar ) import qdarktheme app = QApplication(sys.argv) qdarktheme.setup_theme() main_win = QMainWindow() # Get themed standard icons style = main_win.style() save_icon = style.standardIcon(QStyle.StandardPixmap.SP_DialogSaveButton) open_icon = style.standardIcon(QStyle.StandardPixmap.SP_DialogOpenButton) close_icon = style.standardIcon(QStyle.StandardPixmap.SP_DialogCloseButton) # Create toolbar with themed icons toolbar = QToolBar() toolbar.addAction(open_icon, "Open") toolbar.addAction(save_icon, "Save") toolbar.addAction(close_icon, "Close") main_win.addToolBar(toolbar) # Create buttons with themed icons save_button = QPushButton("Save") save_button.setIcon(save_icon) layout = QVBoxLayout() layout.addWidget(save_button) central_widget = QWidget() central_widget.setLayout(layout) main_win.setCentralWidget(central_widget) main_win.show() app.exec() ``` -------------------------------- ### Customize accent color in PyQtDarkTheme Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Use the custom_colors parameter in setup_theme to define a primary accent color. ```Python qdarktheme.setup_theme(custom_colors={"primary": "#D0BCFF"}) main_win = QMainWindow() main_win.setContentsMargins(10, 10, 10, 10) push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` -------------------------------- ### Stylesheet and Palette Loading API Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/index.md Functions for loading custom stylesheets and color palettes. ```APIDOC ## load_stylesheet() ### Description Loads a stylesheet for the application. ### Method `load_stylesheet(theme: str = None, **kwargs)` ### Endpoint N/A (Function call) ### Parameters - **theme** (str) - Optional - The name of the theme to load. If None, the default theme is used. - **kwargs** - Additional keyword arguments for theme customization. ### Request Example ```python import qdarktheme stylesheet = qdarktheme.load_stylesheet(theme='dark') # or with custom options # stylesheet = qdarktheme.load_stylesheet(theme='dark', custom_color='red') ``` ### Response - **stylesheet** (str) - The generated CSS stylesheet string. ### Response Example ```css /* CSS stylesheet content */ QWidget { background-color: #2b2b2b; color: #ffffff; } ``` ## load_palette() ### Description Loads a color palette for the application. ### Method `load_palette(theme: str = None, **kwargs)` ### Endpoint N/A (Function call) ### Parameters - **theme** (str) - Optional - The name of the theme to load. If None, the default theme is used. - **kwargs** - Additional keyword arguments for palette customization. ### Request Example ```python import qdarktheme from PySide6.QtGui import QPalette palette = qdarktheme.load_palette(theme='dark') # or with custom options # palette = qdarktheme.load_palette(theme='dark', custom_color='blue') ``` ### Response - **palette** (QPalette) - A QPalette object representing the loaded color palette. ### Response Example ```python # Example of how to use the returned QPalette object # app.setPalette(palette) ``` ``` -------------------------------- ### Integration with pyqtgraph Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Shows how PyQtDarkTheme integrates with pyqtgraph, allowing plot background colors to be coordinated with theme changes for a consistent appearance. ```APIDOC ## Integration with pyqtgraph ### Description PyQtDarkTheme works seamlessly with pyqtgraph for scientific visualization applications. Coordinate the plot background color with theme changes for consistent appearance. ### Method GET/POST (conceptual, for theme setup and background setting) ### Endpoint N/A (Python code) ### Parameters None ### Request Example ```python # Coordinate plot background with theme plot_widget.setBackground("k" if theme == "dark" else "w") ``` ### Response #### Success Response (200) - **Plot Background** (string) - The plot background color is updated to match the current theme. ``` -------------------------------- ### Integrate with pyqtgraph Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Coordinate plot background colors with theme changes to maintain visual consistency. ```python import sys import pyqtgraph as pg from PySide6.QtCore import Slot from PySide6.QtWidgets import QApplication, QComboBox, QMainWindow, QVBoxLayout, QWidget import qdarktheme app = QApplication(sys.argv) qdarktheme.setup_theme() main_win = QMainWindow() combo_box = QComboBox() plot_widget = pg.PlotWidget() plot_widget.plot([1, 2, 3, 4, 5], [1, 4, 9, 16, 25]) @Slot(str) def toggle_theme(theme: str) -> None: qdarktheme.setup_theme(theme) # Coordinate plot background with theme plot_widget.setBackground("k" if theme == "dark" else "w") combo_box.addItems(qdarktheme.get_themes()) combo_box.currentTextChanged.connect(toggle_theme) layout = QVBoxLayout() layout.addWidget(combo_box) layout.addWidget(plot_widget) central_widget = QWidget() central_widget.setLayout(layout) main_win.setCentralWidget(central_widget) main_win.show() app.exec() ``` -------------------------------- ### load_palette Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Returns a QPalette object configured for the specified theme, useful for direct palette manipulation. ```APIDOC ## load_palette ### Description Returns a QPalette configured for the specified theme. Useful when you need direct access to theme colors or want to apply only palette-based styling without the full stylesheet. ### Method `load_palette()` ### Parameters #### Keyword Arguments - **theme** (str) - Optional - The theme to load. Options: "dark" (default), "light", "auto". - **corner_shape** (str) - Optional - The shape of widget corners. Options: "rounded" (default), "sharp". - **custom_colors** (dict) - Optional - A dictionary to specify custom accent colors. For "auto" theme, can be a dictionary with keys `"[dark]"` and `"[light]"` to specify different colors for dark and light modes. - **default_theme** (str) - Optional - The fallback theme to use if OS theme detection fails in "auto" mode. Options: "dark", "light". ### Request Example ```python import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Get dark theme palette palette = qdarktheme.load_palette() app.setPalette(palette) # Get light theme palette palette = qdarktheme.load_palette("light") # Auto-detect system theme palette = qdarktheme.load_palette("auto") # Custom colors palette = qdarktheme.load_palette( theme="dark", custom_colors={"primary": "#D0BCFF"} ) # Access theme colors programmatically dark_palette = qdarktheme.load_palette("dark") link_color = dark_palette.link().color() link_rgb = link_color.getRgb() # Returns (R, G, B, A) tuple print(f"Link color RGB: {link_rgb}") main_win = QMainWindow() push_button = QPushButton("Palette Applied!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` ### Response - **palette** (QPalette) - The generated QPalette object. ``` -------------------------------- ### Retrieve Stylesheets with load_stylesheet Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Returns the theme stylesheet as a string for manual application. Useful for combining with other styling approaches or applying to specific widgets. ```python import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Get dark theme stylesheet stylesheet = qdarktheme.load_stylesheet() app.setStyleSheet(stylesheet) # Get light theme stylesheet stylesheet = qdarktheme.load_stylesheet("light") # Auto-detect system theme stylesheet = qdarktheme.load_stylesheet("auto") # Sharp corners with custom colors stylesheet = qdarktheme.load_stylesheet( theme="dark", corner_shape="sharp", custom_colors={"primary": "#00FF00"} ) # Theme-specific color customization stylesheet = qdarktheme.load_stylesheet( theme="auto", custom_colors={ "[dark]": {"primary": "#BB86FC"}, "[light]": {"primary": "#6200EE"} }, default_theme="light" # Fallback theme ) app.setStyleSheet(stylesheet) main_win = QMainWindow() push_button = QPushButton("Custom Styled!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` -------------------------------- ### Customize Accent Color Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/README.md Customize the accent color of the theme by providing a dictionary with the 'primary' key to the custom_colors argument in setup_theme. ```Python # Customize accent color. qdarktheme.setup_theme(custom_colors={\"primary\": \"#D0BCFF\"}) ``` -------------------------------- ### Toggle Theme with pyqtgraph Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Update plot background color when switching themes. ```python def toggle_theme(theme) -> None: qdarktheme.setup_theme(theme) plot_widget.setBackground("k" if theme == "dark" else "w") signal.connect(toggle_theme) ``` ```python import sys import pyqtgraph as pg from PySide6.QtCore import Slot from PySide6.QtWidgets import QApplication, QComboBox, QMainWindow, QVBoxLayout, QWidget import qdarktheme app = QApplication(sys.argv) qdarktheme.setup_theme main_win = QMainWindow() combo_box = QComboBox() plot_widget = pg.PlotWidget() @Slot(str) def toggle_theme(theme) -> None: qdarktheme.setup_theme(theme) plot_widget.setBackground("k" if theme == "dark" else "w") combo_box.addItems(qdarktheme.get_themes()) combo_box.currentTextChanged.connect(toggle_theme) layout = QVBoxLayout() layout.addWidget(combo_box) layout.addWidget(plot_widget) central_widget = QWidget() central_widget.setLayout(layout) main_win.setCentralWidget(central_widget) main_win.show() app.exec() ``` -------------------------------- ### Customize theme color globally Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/tools/build_theme_color_doc/theme_color.template.rst Apply a custom primary color to the theme using the custom_colors dictionary. ```python import qdarktheme qdarktheme.setup_theme(custom_colors={"primary": "#D0BCFF"}) ``` -------------------------------- ### load_stylesheet Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Returns the theme stylesheet as a string without applying it, allowing for manual control over stylesheet application. ```APIDOC ## load_stylesheet ### Description Returns the theme stylesheet as a string without applying it, giving you manual control over how the stylesheet is used. Useful when you need to combine with other styling approaches or apply to specific widgets. ### Method `load_stylesheet()` ### Parameters #### Keyword Arguments - **theme** (str) - Optional - The theme to load. Options: "dark" (default), "light", "auto". - **corner_shape** (str) - Optional - The shape of widget corners. Options: "rounded" (default), "sharp". - **custom_colors** (dict) - Optional - A dictionary to specify custom accent colors. For "auto" theme, can be a dictionary with keys `"[dark]"` and `"[light]"` to specify different colors for dark and light modes. - **default_theme** (str) - Optional - The fallback theme to use if OS theme detection fails in "auto" mode. Options: "dark", "light". ### Request Example ```python import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Get dark theme stylesheet stylesheet = qdarktheme.load_stylesheet() app.setStyleSheet(stylesheet) # Get light theme stylesheet stylesheet = qdarktheme.load_stylesheet("light") # Auto-detect system theme stylesheet = qdarktheme.load_stylesheet("auto") # Sharp corners with custom colors stylesheet = qdarktheme.load_stylesheet( theme="dark", corner_shape="sharp", custom_colors={"primary": "#00FF00"} ) # Theme-specific color customization stylesheet = qdarktheme.load_stylesheet( theme="auto", custom_colors={ "[dark]": {"primary": "#BB86FC"}, "[light]": {"primary": "#6200EE"} }, default_theme="light" # Fallback theme ) app.setStyleSheet(stylesheet) main_win = QMainWindow() push_button = QPushButton("Custom Styled!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` ### Response - **stylesheet** (str) - The generated Qt stylesheet string. ``` -------------------------------- ### Clear Cache Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Clears PyQtDarkTheme's resource caches stored in the system's home path. This is useful for troubleshooting or forcing a complete refresh of theme resources. ```APIDOC ## clear_cache ### Description Clears PyQtDarkTheme's resource caches stored in the system home path. Useful for troubleshooting or forcing a complete refresh of theme resources. ### Method POST (conceptual) ### Endpoint N/A (Python function) ### Parameters None ### Request Example ```python qdarktheme.clear_cache() ``` ### Response #### Success Response (200) No explicit response body, the cache is cleared. ``` -------------------------------- ### Set Sharp Corner Shape Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/README.md Change the corner shape of widgets to 'sharp' by passing the corner_shape argument to setup_theme. The default is 'rounded'. ```Python # Default is "rounded". stylesheet = qdarktheme.setup_theme(corner_shape="sharp") ``` -------------------------------- ### Append custom stylesheets Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Pass a custom QSS string to the additional_qss parameter to extend or override theme styles. ```Python qss = """ QPushButton { border-width: 2px; border-style: dashed; } """ qdarktheme.setup_theme(additional_qss=qss) ``` ```default import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Additional stylesheet qss = """ QPushButton { border-width: 2px; border-style: dashed; } """ qdarktheme.setup_theme(additional_qss=qss) main_win = QMainWindow() main_win.setContentsMargins(10, 10, 10, 10) push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` -------------------------------- ### Stop OS theme synchronization with stop_sync Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Call this to disable automatic OS theme tracking, allowing manual control over the theme. ```python import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget import qdarktheme app = QApplication(sys.argv) # Start with OS theme sync qdarktheme.setup_theme("auto") main_win = QMainWindow() # Button to stop syncing and lock to dark theme def lock_dark_theme(): qdarktheme.stop_sync() qdarktheme.setup_theme("dark") lock_button = QPushButton("Lock Dark Theme") lock_button.clicked.connect(lock_dark_theme) layout = QVBoxLayout() layout.addWidget(lock_button) central_widget = QWidget() central_widget.setLayout(layout) main_win.setCentralWidget(central_widget) main_win.show() app.exec() ``` -------------------------------- ### Customize theme color for a specific theme Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/tools/build_theme_color_doc/theme_color.template.rst Target a specific theme variant by using the theme name as a key within the custom_colors dictionary. ```python import qdarktheme qdarktheme.setup_theme( custom_colors={ "[dark]": { "primary": "#D0BCFF", } } ) ``` -------------------------------- ### Customize Theme Colors Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Override specific theme colors using the custom_colors argument. ```python qdarktheme.setup_theme(custom_colors={"primary": "#D0BCFF"}) ``` ```python import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) qdarktheme.setup_theme(custom_colors={"primary": "#D0BCFF"}) main_win = QMainWindow() push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` -------------------------------- ### Stop System Theme Synchronization Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/reference/qdarktheme.md Stops the application from syncing with the operating system's theme settings. ```python qdarktheme.stop_sync() ``` -------------------------------- ### Stop Theme Synchronization Source: https://context7.com/5yutan5/pyqtdarktheme/llms.txt Stops the automatic OS theme synchronization listener. This is useful when you want to manually control the theme after initial synchronization. ```APIDOC ## stop_sync ### Description Stops the automatic OS theme synchronization listener that was started by `setup_theme("auto")`. Use this when you want to manually control the theme after initially syncing. ### Method POST (conceptual) ### Endpoint N/A (Python function) ### Parameters None ### Request Example ```python qdarktheme.stop_sync() ``` ### Response #### Success Response (200) No explicit response body, the synchronization listener is stopped. ``` -------------------------------- ### Change border corner shape Source: https://github.com/5yutan5/pyqtdarktheme/blob/main/docs/source/how_to_use.md Set the corner_shape parameter to 'sharp' to modify the UI border style. ```Python qdarktheme.setup_theme(corner_shape="sharp") ``` ```default import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton import qdarktheme app = QApplication(sys.argv) # Change border corner shape to sharp. qdarktheme.setup_theme(corner_shape="sharp") main_win = QMainWindow() main_win.setContentsMargins(10, 10, 10, 10) push_button = QPushButton("PyQtDarkTheme!!") main_win.setCentralWidget(push_button) main_win.show() app.exec() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.