Hello,

I have a project with a QTableView and a corresponding QAbstractTableModel. I have implemented a filter that can be applied to multiple columns. I need the column color (just the header section, not the entire column of the QTableView) to change if a filter is being applied to that column. I've made a couple of attempts and did not succeed. I'm starting to wonder if this is even possible.

I tried setting the stylesheet, but it didn't do anything:

Qt Code:
  1. QHeaderView::section:selected
  2. {
  3. background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
  4. stop:0 #00FF00, stop:1 #004C00);
  5. }
To copy to clipboard, switch view to plain text mode 

I tried connecting the sectionClicked(int) signal in the QHeaderView to the model, to store the lastColumn clicked, and use this in headerData() to return a color if the role== Qt::BackgroundColorRole, but this did not work either.

Qt Code:
  1. QVariant OrderTableModel::headerData(int section, Qt::Orientation orientation, int role) const
  2. {
  3. ...
  4. else if (role == Qt::BackgroundColorRole)
  5. {
  6. if (orientation == Qt::Horizontal) {
  7. if (section == m_nSectionClicked)
  8. {
  9. return QBrush(Qt::darkBlue);
  10. }
  11. else
  12. {
  13. return QBrush(Qt::black);
  14. }
  15. }
  16. }
  17. ...
  18. }
To copy to clipboard, switch view to plain text mode