Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2290

Issues with QStyleHints colorScheme: ColorScheme.Unknown and colorSchemeChanged Signal not working

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 6.5.0
    • PySide
    • None
    • Windows 10 Home 22H2
      Using kit Desktop Qt 6.5.0 MinGW 64-bit
    • Windows

    Description

      I have the following main.py file :

      # This Python file uses the following encoding: utf-8
      import sys
      from pathlib import Path
      
      from PySide6.QtWidgets import QApplication
      from PySide6.QtQml import QQmlApplicationEngine
      from PySide6.QtGui import QStyleHints
      from PySide6.QtCore import Qt
      
      import threading
      import time
      
      def print_hello_world():
          hints = QStyleHints()
          while True:
              print(hints.colorScheme())
              time.sleep(1)
      
      t = threading.Thread(target=print_hello_world)
      t.daemon = True
      t.start()
      
      if __name__ == "__main__":
          app = QApplication(sys.argv)
          engine = QQmlApplicationEngine()
          hints1 = QStyleHints()
          hints1.colorSchemeChanged.connect(lambda: print("hi"))
          qml_file = Path(__file__).resolve().parent / "main.qml"
          engine.load(qml_file)
      
          if not engine.rootObjects():
              sys.exit(-1)
          sys.exit(app.exec())
      

      as well as this Main.qml file (with imports and other parts removed for brevity):

      Window {
          id: root
          width: 800
          height: 600
          visible: true
          title: qsTr("Test")
      
          Material.theme: Material.System
          color: Material.background
      }
      

       

      When running the app with Windows 10's overall theme set to Light, the print statement inside the print_hello_world() function repeatedly displays:

      ColorScheme.6357104

      Closing and restarting the application with the same parameters yields a different number i.e.

      ColorScheme.7667811

      or

      ColorScheme.32767

      Sometimes, ColorScheme.Unknown is printed. 

      Moreover, the colorSchemeChanged signal fails to react to any theme changes.
      The ColorScheme that gets printed remains unchanged throughout theme changes, meaning if it were printing ColorScheme.32767 when Windows is in Light mode, it still prints the same thing as soon as Windows switches to Dark mode.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            factor5143 Cube Root
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes