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

QDockWidget titlebars not dark-light mode updated on macOS if stylesheet set

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • P2: Important
    • None
    • 6.5
    • Widgets: Styles
    • None
    • macos Qt 6
    • All

    Description

      On macOS, if you switch from dark to light or light to dark mode while a Qt app is open and that app loads a qss stylesheet and uses QDockWidgets, the titlebar of the QDockWidgets never get properly updated.

      This only happens when the app loads a stylesheet.

      I have created a standalone test case from your official dockwidgets example.

      It uses qmake to build.

      unzip dockwidget_bug.zip
      cd dockwidget_bug
      qmake
      make
      open ./dockwidgets.app

      When open, simply go to macOS System Settings Appearance and change light to dark mode or visa-versa.

      You will see the QDockwidget titlebars are not properly repainted.

      The only way around this I have found is to use something like the following in the QDockWidget subclass to override the paintEvent and force the titlebar to be painted properly:

      ```

      void BookBrowser::paintEvent(QPaintEvent *event)
      {
          QStylePainter painter(this);
          if (isFloating()) {
              QStyleOptionFrame options;
              options.initFrom(this);
      
      #ifdef Q_OS_MAC
              // This is needed for Qt6 but works on Qt5 as well
              options.palette = QApplication::palette();
      #endif
      
              painter.drawPrimitive(QStyle::PE_FrameDockWidget, options);
          }
          QStyleOptionDockWidget options;
          initStyleOption(&options);
          options.title = windowTitle();
      
      #ifdef Q_OS_MAC
          // This is needed for Qt6 but works on Qt5 as well
          options.palette = QApplication::palette();
      #endif
      
          painter.drawControl(QStyle::CE_DockWidgetTitle, options);
      }
      

      ```

      Attachments

        1. closedock-macstyle.svg
          0.9 kB
        2. dockdock-macstyle.svg
          0.8 kB
        3. dockwidget_bug.zip
          13 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            axelspoerl Axel Spoerl
            kevinhendricks Kevin B. Hendricks
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes