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

Setting background brush in QTableWidgetItem used as header item is incorrectly cached leading to incorrect display colours

    XMLWordPrintable

Details

    • All
    • 109e088c7c (qt/qtbase/dev) 109e088c7c (qt/tqtc-qtbase/dev) 124a8c20ed (qt/qtbase/6.4) 124a8c20ed (qt/tqtc-qtbase/6.4) bf6cad8ba5 (qt/tqtc-qtbase/6.2)

    Description

      Setting background colours to a QTableWidgetItem that is used as a horizontal header item in QTableWidget doesn't display correctly in 'fusion' style.

      I believe this is due to the `QPalette::cacheKey()` being equal for palette with different background brushes, as in QFusionStyle::drawControl under case CE_HeaderSection: reuses the same cached pixmap for at least some of the header items.

      Can be reproduced using the following code added to WidgetGallery::createBottomLeftTabWidget() in the 'styles' example: 

      tableWidget->setColumnCount(4);
      const auto headerColours = std::vector<QColor>{Qt::GlobalColor::red, Qt::GlobalColor::blue, Qt::GlobalColor::green};
      for (size_t i=0; i<headerColours.size(); ++i)
      {
        const auto &colour = headerColours[i];
        auto headerItem = new QTableWidgetItem("");
        headerItem->setBackground(colour);
        tableWidget->setHorizontalHeaderItem(i, headerItem);
      }

       

      When displaying in 'fusion mode' the headers are coloured incorrectly in Qt 6:

       

      In Qt 5 they are displayed correctly:

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-106984
          # Subject Branch Project Status CR V

          Activity

            People

              vhilshei Volker Hilsheimer
              jonsmith Jon Smith
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes