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

Using QItemDelegate on QTreeWidget changes selection background and text color

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.14.2, 5.15
    • Fix Version/s: None
    • Component/s: Widgets: Itemviews
    • Labels:
      None
    • Platform/s:
      Windows

      Description

      Setting a QItemDelegate on a QTreeWidget columns ends up with selection blue color being different and also text being white instead of black.

      See sample program:

      #include <QApplication>
      #include <QMainWindow>
      #include <QTreeWidget>
      #include <QItemDelegate>
      #include <QVBoxLayout>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);    
      
          QMainWindow w;
      
          QWidget* centralWidget = new QWidget(&w);
          w.setCentralWidget(centralWidget);
          centralWidget->setLayout( new QVBoxLayout() );
      
          QTreeWidget* tree = new QTreeWidget();
          tree->setColumnCount(2);
          centralWidget->layout()->addWidget( tree );
      
          QTreeWidgetItem* item = new QTreeWidgetItem();
          item->setText( 0, "No QItemDelegate" );
          item->setText( 1, "With QItemDelegate" );
      
          tree->addTopLevelItem( item );
          tree->setItemDelegateForColumn( 1, new QItemDelegate() );
          
          w.show();
          return app.exec();
      }

      See resulting display in attached image. The whole row should be highlighted with the same color.

      It not not look nice in the end when the whole line is selected and also it leads to problems if you try to use delegate to display html (because your black text is almost invisible whith the dark blue background bsing used).

        Attachments

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

          Activity

            People

            Assignee:
            qt.team.quick.subscriptions Qt Quick and Widgets Team
            Reporter:
            jpo38 Jean Porcherot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes