Solved QTreeView: change background color of specific column header
-
Is it possible to change the background color of a specific column of QTreeView header?
This can change the background color of all columns:
ui->tree->setStyleSheet("QHeaderView::section { background-color:red }");
This is not working:
ui->tree->model()->setHeaderData(col, Qt::Horizontal, QBrush(QColor("red")), Qt::BackgroundRole);
Is there any ideas?
Thank you!
-
Hi,
The style used to draw your application is free to ignore certain hints to follow the OS style they represent. That's why your second line may have no effect.
-
I tried to use default and Fusion styles:
QApplication::setStyle(QStyleFactory::create("Fusion"));
Style was changed.
The header cell is empty for both styles as a result.
-
Please provide a minimal compilable example that reproduces this.
-
Hi!
Problem solved by redefinition of QHeaderView::paintSection.
Thank you!