Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How do I customizing QTreeView header by stylesheet



  • 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



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


  • Moderators

    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.


Log in to reply