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[源代码]#

Apply the theme which looks like flat design to the Qt App completely.

This function applies the complete style to your Qt application. If the argument theme is auto, try to listen to changes to the OS’s theme and switch the application theme accordingly.

参数
  • theme – The theme name. There are dark, light and auto. If auto, try to sync with your OS’s theme and accent (accent is only on Mac). If failed to detect OS’s theme, use the default theme set in argument default_theme. When primary color(primary) or primary child colors (such as primary>selection.background) are set to custom_colors, disable to sync with the accent.

  • 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.

引发
  • ValueError – If the argument is wrong.

  • KeyError – If the color id of custom_colors is wrong.

返回

The stylesheet string for the given arguments.

实际案例

Set stylesheet to your Qt application.

  1. Setup style and sync to system theme

    app = QApplication([])
    qdarktheme.setup_theme()
    
  2. Use Dark Theme

    app = QApplication([])
    qdarktheme.setup_theme("dark")
    
  3. Sharp corner

    # Change corner shape to sharp.
    app = QApplication([])
    qdarktheme.setup_theme(corner_shape="sharp")
    
  4. Customize color

    app = QApplication([])
    qdarktheme.setup_theme(custom_colors={"primary": "#D0BCFF"})
    
  5. Customize a specific theme only

    app = QApplication([])
    qdarktheme.setup_theme(
        theme="auto",
        custom_colors={
            "[dark]": {
                "primary": "#D0BCFF",
            }
        },
    )
    
qdarktheme.enable_hi_dpi() None[源代码]#

Allow to HiDPI.

This function must be set before instantiation of QApplication.. For Qt6 bindings, HiDPI “just works” without using this function.

qdarktheme.stop_sync() None[源代码]#

Stop sync with system theme.

qdarktheme.load_stylesheet(theme: str = 'dark', corner_shape: str = 'rounded', custom_colors: Optional[dict[str, str | dict[str, str]]] = None, *, default_theme: str = 'dark') str[源代码]#

Load the style sheet which looks like flat design. There are dark and light theme.

参数
  • theme – The theme name. There are dark, light and auto. If auto, try to detect your OS’s theme and accent (accent is only on Mac). If failed to detect OS’s theme, use the default theme set in argument default_theme. When primary color(primary) or primary child colors (such as primary>selection.background) are set to custom_colors, disable to detect the accent.

  • 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.

引发
  • ValueError – If the arguments of this method is wrong.

  • KeyError – If the color id of custom_colors is wrong.

返回

The stylesheet string for the given arguments.

实际案例

Set stylesheet to your Qt application.

  1. Dark Theme

    app = QApplication([])
    app.setStyleSheet(qdarktheme.load_stylesheet())
    # or
    app.setStyleSheet(qdarktheme.load_stylesheet("dark"))
    
  2. Light Theme

    app = QApplication([])
    app.setStyleSheet(qdarktheme.load_stylesheet("light"))
    
  3. Automatic detection of system theme

    app = QApplication([])
    app.setStyleSheet(qdarktheme.load_stylesheet("auto"))
    
  4. Sharp corner

    # Change corner shape to sharp.
    app = QApplication([])
    app.setStyleSheet(qdarktheme.load_stylesheet(corner_shape="sharp"))
    
  5. Customize color

    app = QApplication([])
    app.setStyleSheet(qdarktheme.load_stylesheet(custom_colors={"primary": "#D0BCFF"}))
    
  6. 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)[源代码]#

Load the QPalette for the dark or light theme.

参数
  • 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 argument default_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 link and placeholder.

引发
  • TypeError – If the arg name of theme is wrong.

  • KeyError – If the color id of custom_colors is wrong.

返回

The QPalette for the given theme.

返回类型

QPalette

实际案例

Set QPalette to your Qt application.

  1. Dark Theme

    app = QApplication([])
    app.setPalette(qdarktheme.load_palette())
    # or
    app.setPalette(qdarktheme.load_palette("dark"))
    
  2. Light Theme

    app = QApplication([])
    app.setPalette(qdarktheme.load_palette("light"))
    
  3. Automatic detection of system theme

    app = QApplication([])
    app.setPalette(qdarktheme.load_palette("auto"))
    
  4. Customize color

    app = QApplication([])
    app.setPalette(custom_colors={"primary": "#D0BCFF"})
    
  5. Customize a specific theme only

    app = QApplication([])
    app.setStyleSheet(
        qdarktheme.load_stylesheet(
            theme="auto",
            custom_colors={
                "[dark]": {
                    "primary": "#D0BCFF",
                }
            },
        )
    )
    
qdarktheme.get_themes() tuple[str, ...][源代码]#

Return available theme names.

返回

Tuple of available theme names.

qdarktheme.clear_cache() None[源代码]#

Clear the caches in system home path.

PyQtDarkTheme build the caches of resources in the system home path. You can clear the caches by running this method.