Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-117385

QDialog flashes light mode before redrawing in dark mode

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.5.2
    • None
    • Python 3.10.12, PySide 6.5.2, Windows 10
    • Windows

    Description

      1. Run the following example.
      2. Click the tray icon, and then "QDialog" from the tray menu.
      3. EXPECTED: QDialog consistently displays only in dark mode.
      4. ACTUAL: QDialog intermittently displays in light mode before quickly refreshing in dark mode, perceived as a flash from light to dark.
      5. Click "Ok" and repeat step 2 several times.
      from PySide6.QtCore import Qt
      from PySide6.QtGui import QIcon
      from PySide6.QtWidgets import QApplication, QDialog, QDialogButtonBox, QLabel, QMenu, QPushButton, QSystemTrayIcon, QVBoxLayout, QStyle, QWidget
      import sys
      
      class DarkQDialogMayFlashLightFirst(QSystemTrayIcon):
          def __init__(self, _icon):
              super().__init__(_icon)
              self.tray_icon = QSystemTrayIcon
              self.tray_menu = QMenu()
              self.tray_menu.addAction('Exit', QApplication.exit)
              self.tray_menu.addAction('QDialog', self.dialog)
              self.setContextMenu(self.tray_menu)
      
          @staticmethod
          def dialog():
              text = '\n' * 30
              labelText = QLabel(text)
              buttonOk = QPushButton('Ok')
              buttonOk.clicked.connect(lambda: dialog.close())
              buttons = QDialogButtonBox()
              buttons.addButton(buttonOk, QDialogButtonBox.AcceptRole)
              layout = QVBoxLayout()
              layout.addWidget(labelText)
              layout.addWidget(buttons)
              dialog = QDialog()
              dialog.setLayout(layout)
              dialog.exec()
      
      sys.argv += ['-platform', 'windows:darkmode=2']
      
      def main():
          app = QApplication(sys.argv)
          app.setQuitOnLastWindowClosed(False)
          app.setStyle('Fusion')
      
          app_icon = QApplication.style().standardIcon(QStyle.StandardPixmap.SP_MessageBoxQuestion)
      
          tray_icon = DarkQDialogMayFlashLightFirst(app_icon)
          tray_icon.show()
      
          sys.exit(app.exec())
      
      if __name__ == '__main__':
          main()
      

      Attachments

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

        Activity

          People

            owolff Oliver Wolff
            particleman particleman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes