
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 0.82 KB | hits: 22 | expires: Never
How to change the header background color of a QTableView
template<typename T>
inline QVariant TableModel<T>::headerData(int section, Qt::Orientation orientation, int role) const
{
//...
else if(role == Qt::BackgroundRole) {
return QBrush(m_display.headerBackground);
}
//...
}
ui->tableView->setStyleSheet("QHeaderView::section { background-color:red }");
MyTableView::MyTableView( QWidget* parent ) : QTableView( parent )
{
...
// Make a copy of the current header palette.
QPalette palette = horizontalHeader()->palette();
// Set the normal/active, background color
// QPalette::Background is obsolete, use QPalette::Window
palette.setColor( QPalette::Normal, QPalette::Window, Qt::red );
// Set the palette on the header.
horizontalHeader()->setPalette( palette );
}