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

QTreeview branch can't use transparent background

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P2: Important
    • None
    • 5.15.2
    • Widgets: Itemviews
    • None
    • Windows

    Description

      #include "MainWindow.h"
      
      #include <QApplication>
      #include <QFileSystemModel>
      #include <QTreeView>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          MainWindow w;
      
          // Create a file system model
          QFileSystemModel model;
          model.setRootPath("");
      
          // Create the QTreeView instance and set up the model
          QTreeView treeView(&w);
          treeView.setModel(&model);
          treeView.setRootIndex(model.index("")); // Set the root directory
          // Define the QSS style directly in code
          QString qss = "\
              QTreeView {\
                  border: none;\
                  border-top: 1px solid #14000000;\
                  padding: 4px;\
                  show-decoration-selected: 1;\
          }\
              QTreeView::item {\
                  outline: none;\
                  color: #101010;\
          }\
              QTreeView::item:hover, QTreeView::branch:hover {\
                  background: #19203030;\
          }\
              QTreeView::item:selected, QTreeView::branch:selected {\
                  background: #1900FFFF;\
                  outline: none;\
          }";
      
              treeView.setStyleSheet(qss); // apply style
          w.setCentralWidget(&treeView);
          w.show();
          return a.exec();
      }
      

      If you use the above code and click on a row, you will notice that the branch part is displayed in dark blue. If you replace "#1900FFFF" with a non-transparent color like "#E6FFFF", you won't encounter this issue.

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            0ices zero ices
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes