Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I customizing QTreeView header by stylesheet
Forum Updated to NodeBB v4.3 + New Features

How do I customizing QTreeView header by stylesheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 7.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    graniteDev
    wrote on 30 Jul 2018, 21:24 last edited by
    #1

    I am trying to style the header of a QTreeView but there is nothing in the style sheet examples page pertaining to the header.

    my code

        m_model = new QStandardItemModel(this);
        m_model->setHorizontalHeaderItem(0,new QStandardItem(QString("Key")));
        m_model->setHorizontalHeaderItem(1,new QStandardItem(QString("Value")));
        ui->treeView->setModel(m_model);
    
        QFile styleSheet = "./style/vmapViewer.qss";
        styleSheet.open(QFile::ReadOnly);
        ui->treeView->setStyleSheet(styleSheet.readAll());
        styleSheet.close();
    

    my style sheet

    QWidget {
        background-color: #2D3D46;
    }
    
    QTreeView {
        alternate-background-color: #171E22;
    }
    QTreeView::branch {
        color: #fff;
    }
    QHeaderView {
        color: #fff;
        background-color: #000;
    }
    

    but as you can see, the headers are still white, along with the text

    0_1532985698049_373e59cf-0ceb-4ef4-a954-4d8da232c85a-image.png

    1 Reply Last reply
    0
    • G Offline
      G Offline
      graniteDev
      wrote on 31 Jul 2018, 11:43 last edited by
      #2

      OK....then does anyone know how to find all the style sheet options for a particular object?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 31 Jul 2018, 12:42 last edited by
        #3

        Headers are implemented via QHeaderView class so you need to style that, not QTreeView. See here for an example and here for a list of supported sub-controls and pseudo states.

        1 Reply Last reply
        3

        1/3

        30 Jul 2018, 21:24

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved