Giter Club home page Giter Club logo

pyqt-windows-os-light-dark-theme-window's Introduction

pyqt-windows-os-light-dark-theme-window

PyQt windows which detects Windows dark/light theme settings and changes the theme dynamically

This is for Windows only. I tested this in Windows 11. This app might work in Windows 10 as well.

Detailed Description

This is using Windows DWMAPI library, winreg for get the window registry's value, nativeEvent to change the theme.

As you might know, Windows can change the theme light to dark, or dark to light. This window detects such a thing and apply it to the frame.

You can make it unable to detect the theme if you don't want to change the current window theme accordance with the system theme. See the Method Overview below.

Requirements

  • PyQt5

Install

git clone ~

or

python -m pip install pyqt-windows-os-light-dark-theme-window --upgrade

Method/Signal Overview

Methods

  • setDarkTheme(f: bool) - If you want to set Windows theme directly, use this. If you give True, dark theme will be set to qt window.
  • isDetectingThemeAllowed() -> bool - Check if detecting theme feature is allowed.
  • allowDetectingTheme(f: bool) - Allow detecting theme to change the Windows system theme in real-time. True in default.

Signal

  • changedToDark(bool) - If theme changed, this signal will be emitted.

Code Sample

Note: You don't need this code sample if you cloned this repo, just run the sample.py and you can see the fine result. This code sample is for the people who installed this with pip.

from PyQt5.QtWidgets import QPushButton, QGridLayout, QApplication

from pyqt_windows_os_light_dark_theme_window.main import Window


class MainWindow(Window):
    def __init__(self):
        super().__init__()
        self.__initUi()

    def __initUi(self):
        btn = QPushButton('Theme Toggle')
        btn.setCheckable(True)
        btn.toggled.connect(self.__themeToggled)
        lay = QGridLayout()
        lay.addWidget(btn)
        self.setLayout(lay)
        self.changedToDark.connect(self.__darkThemeOn)

    def __themeToggled(self, f):
        self.setDarkTheme(f)

    def __darkThemeOn(self, f):
        print(f'Is current theme dark?: {f}')


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())

Preview

Windows light theme (as you expected)

image

Windows dark theme

image

pyqt-windows-os-light-dark-theme-window's People

Contributors

yjg30737 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

pyqt-windows-os-light-dark-theme-window's Issues

Some Questions

Hello. Here's some questions for you.

  1. I tried to trigger the toggle button, but it couldn't update the theme automatically, which means you need to double-click the title or change the size of the interface to update the theme.
  2. The theme cannot be applied to all of the sub-widgets, like QMessageBox, AboutUs, QDialogue, etc. Maybe you could improve the function of this package.
    Looking forward to your reply^^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.