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

New native style for Windows 11 ignores stylesheet in some cases

    XMLWordPrintable

Details

    • Windows
    • b733d31f2 (dev), 5cdac10b4 (dev)

    Description

      I found this problem when trying to specify a text color on QToolButton, using stylesheet.

      The text color specified by stylesheet does not work (when mouse cursor not hovering) since upgraded to Qt 6.7, which introduces a new windows 11 native style that seems hard-coded many colors, ignoring the palette configured by stylesheet.

      In the source code (qwindows11style.cpp) for rendering QToolButton, it is obvious that when the QToolButton being rendered is not in "raised" state, a hard-coded color is used instead of palette color.

      if (toolbutton->state & State_Raised)
          painter->setPen(QPen(toolbutton->palette.buttonText().color()));
      else
          painter->setPen(QPen(WINUI3Colors[colorSchemeIndex][controlTextSecondary]));
      proxy()->drawItemText(painter, QStyle::visualRect(toolbutton->direction, rect, tr), alignment, toolbutton->palette, toolbutton->state & State_Enabled, text);
      
      

      This behavior violates the statement in Qt documentation which says:

      "Style sheets are applied on top of the current widget style, meaning that your applications will look as native as possible, but any style sheet constraints will be taken into consideration. Unlike palette fiddling, style sheets offer guarantees: If you set the background color of a QPushButton to be red, you can be assured that the button will have a red background in all styles, on all platforms."

      Seeing the source code I thought that the text color problem I found on QToolButton is unlikely just a standalone case violating the styling precedence cited above. Many other widgets may be also somehow affected.

       

      Attachments

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

        Activity

          People

            tpochep Timur Pocheptsov
            mizusato mizusato
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There is 1 open Gerrit change