Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.82 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to change the header background color of a QTableView
  2. template<typename T>
  3. inline QVariant TableModel<T>::headerData(int section, Qt::Orientation orientation, int role) const
  4. {
  5.     //...
  6.     else if(role == Qt::BackgroundRole) {
  7.         return QBrush(m_display.headerBackground);
  8.     }
  9.     //...
  10. }
  11.        
  12. ui->tableView->setStyleSheet("QHeaderView::section { background-color:red }");
  13.        
  14. MyTableView::MyTableView( QWidget* parent ) : QTableView( parent )
  15. {
  16.     ...
  17.     // Make a copy of the current header palette.
  18.     QPalette palette = horizontalHeader()->palette();
  19.  
  20.     // Set the normal/active, background color
  21.     // QPalette::Background is obsolete, use QPalette::Window
  22.     palette.setColor( QPalette::Normal, QPalette::Window, Qt::red );
  23.  
  24.     // Set the palette on the header.
  25.     horizontalHeader()->setPalette( palette );
  26. }