Search code examples
c++cssqtqwidget

How to set the QTreeWidget's header color and hide the dividing line?


I want to change the background color of the header when I use the QWidget. I tried the following methods but they didn't work:

QTreeWidgetItem * header = ui->treeWidget->headerItem(); 
header->setBackground(0, QBrush(QColor(185,192,201)));
header->setBackgroundColor(0, QColor(185,192,201));

setStyleSheet("QHeaderView::section { background-color:red }");

I also want to know how to hide the header's dividing line?

enter image description here


Solution

  • I've found a method to change the header's style,but I don't know why my previous method did not work.

    QHeaderView::section {                          
        color: black;                               
        padding: 2px;                               
        height:20px;                                
        border: 0px solid #567dbc;                  
        border-left:0px;                            
        border-right:0px;                           
        background: #f9f9f9;                        
    }