Reputation: 51
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?
Upvotes: 1
Views: 3693
Reputation: 51
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;
}
Upvotes: 1
Reputation: 5
As you can read here (and as you see in your example) setBackgroundColor
does not work for header item (I suspect that this is due to difference between header and row items).
You should to reimplement QHeaderView
or to try option described above.
Upvotes: 0
Reputation: 4125
Why don't you use only the stylesheet?
YourQTreeWidget QHeaderView::section {
background-color: red; // for the bakcground
border-right: none; // right-border of each section
border-left: none; // left border of each section
}
Upvotes: 0