Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How does PyQt5 handle system dark and light mode transitions?
QtWS25 Last Chance

How does PyQt5 handle system dark and light mode transitions?

Scheduled Pinned Locked Moved Qt for Python
4 Posts 3 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Toastito
    wrote on last edited by
    #1

    I am working on a PyQt5 desktop application on macOS Sequoia 15.0 with PyQt5 5.15.10.

    While the application is running, when I toggle between the macOS system light and dark mode the application changes the colors of my app, except for the styles I have applied directly with a stylesheet. (See app images below)

    1. What event in PyQt/Qt is causing this interaction to happen automatically?
    2. If possible, how do I control or at the very least disable this behavior?

    Ideally, I could intercept the event (if it is one) and apply my custom stylings like adding light and dark modes. See the images below as an example. The app was built with dark mode in mind. The issue is when the system changes from dark to light mode the text changes from white to black.

    Light Mode

    • Widget text is hard to read
      system_light_mode.png

    Dark Mode

    • Styles look as expected
      system_dark_mode.png
    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      If you where using PyQt/Side6, this stack overflow thread would have given you the information you need.

      Note that using style sheets, the style that renders it is not theme nor plateform aware.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • T Offline
        T Offline
        Toastito
        wrote on last edited by
        #3

        Hi,

        Thanks for the response! I see, so that functionality is available in PyQt6 with the use of styleHints and colorScheme.

        I can achieve the functionality I want in PyQt5, but it would require me to manually check the system theme changes automatically in the background.

        The downside is that PyQt5 will still send a palleteChanged signal/event when the system theme changes. Ideally, I would've been able to block it and implement my own.

        Either way thanks for the response! Inevitably, I'll likely update PyQt5 to 6 and handle system theme transitions as the stack overflow thread suggests.

        jeremy_kJ 1 Reply Last reply
        0
        • T Toastito

          Hi,

          Thanks for the response! I see, so that functionality is available in PyQt6 with the use of styleHints and colorScheme.

          I can achieve the functionality I want in PyQt5, but it would require me to manually check the system theme changes automatically in the background.

          The downside is that PyQt5 will still send a palleteChanged signal/event when the system theme changes. Ideally, I would've been able to block it and implement my own.

          Either way thanks for the response! Inevitably, I'll likely update PyQt5 to 6 and handle system theme transitions as the stack overflow thread suggests.

          jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by
          #4

          @Toastito said in How does PyQt5 handle system dark and light mode transitions?:

          The downside is that PyQt5 will still send a palleteChanged signal/event when the system theme changes. Ideally, I would've been able to block it and implement my own.

          I haven't tried, but would expect an event filter to be able to filter out PaletteChange events.

          The QGuiApplication::paletteChanged signal doesn't appear to be connected to anything by default. QObject::disconnect() without a receiver would ensure that, for any existing objects at the time of the call. Note that disconnecting signals at random can have surprising results.

          Asking a question about code? http://eel.is/iso-c++/testcase/

          1 Reply Last reply
          1
          • T Toastito marked this topic as a regular topic on

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved