I have a QTableView that is based on a SQLRelational model. I subclassed QSortFilterProxyModel to be able to use the data() function to color certain cells based on a previous determination of the row. I was able to sucessfully do that, however if the user sorts the table by clicking on the header, the table sorts properly but the cells (not the correct data) that were previously highlighted are still highlighted. How do I get the data() function to get called after the sort is completed? I thought that I could emit a dataChanged signal, but it doesn't seem to work. Is this the proper way of doing this or is there a better way?
MainClass.h
Qt Code:
  1. #include <QSqlRelationalTableModel>
  2. #include<QSortFilterProxyModel>
  3. #include "myproxymodel.h"
  4.  
  5. MyProxyModel* proxy;
  6. QHeaderView *horizHeader;
  7. class MyProxyModel;
To copy to clipboard, switch view to plain text mode 
MainClass.cpp
Qt Code:
  1. void MainClass::createReportTable(QStringList stringList)
  2. {
  3. mReportOptions=stringList;
  4.  
  5. printModel= new QSqlRelationalTableModel (this);
  6. printModel-> setEditStrategy(QSqlTableModel::OnRowChange);
  7. printModel-> setTable (mTableName);
  8. printModel-> setRelation (2, QSqlRelation("LName", "id", "Last Name"));
  9. printModel->select();
  10. proxy = new MyProxyModel(this);
  11. proxy->setSourceModel(printModel);
  12. ui->printView->setModel(proxy);
  13. horizHeader= ui->printView->horizontalHeader();
  14.  
  15.  
  16. connect(this,SIGNAL(sendRows(int, int)), // to send the selected rows to the proxy
  17. proxy, SLOT(getRows(int, int)));
  18. connect(horizHeader, SIGNAL(sortIndicatorChanged (int) ), //This dooesn't seem to work
  19. proxy,SIGNAL(dataChanged ( ) )); //this was to capture the click on the header and repopulate the table
  20.  
  21. ui->printView->setSelectionMode(QAbstractItemView::SingleSelection);
  22. ui->printView->setSelectionBehavior(QAbstractItemView::SelectRows);
  23.  
  24. printModel->setFilter(mFilterString);
  25. printModel->select();
  26. highlightCells();
  27.  
  28. void MainClass::highlightCells()
  29. {
  30. float lowSale=FLT_MAX;
  31. float highSale=FLT_MIN;
  32. float currentSales;
  33. int rowHigh=0;
  34. int rowLow=0;
  35. int numRows =proxy->rowCount();
  36.  
  37. for (int r=0; r<numRows; r++ )
  38. {
  39. if (ui->printView->isRowHidden(r))
  40. continue;
  41. currentSales = proxy->index(r,5).data(Qt::DisplayRole).toFloat();
  42. if (currentSales < lowSale)
  43. {
  44. lowSale = currentSale;
  45. rowLow = r;
  46. }
  47. if (currentSale > highSale)
  48. {
  49. highSale = currentSale;
  50. rowHigh = r;
  51. }
  52. }
  53.  
  54. emit sendRows (rowSlow, rowFast);
  55. }
To copy to clipboard, switch view to plain text mode 

myproxymodel.cpp
Qt Code:
  1. #include "myproxymodel.h"
  2.  
  3. MyProxyModel::MyProxyModel (QObject *parent) :
  4. {
  5.  
  6. }
  7. MyProxyModel::~MyProxyModel()
  8. {
  9.  
  10. }
  11.  
  12. QVariant MyProxyModel::data ( const QModelIndex & index, int role ) const
  13. {
  14.  
  15. if (!index.isValid())
  16. return QVariant();
  17. if ( index.row() == m_lowRow && index.column()== 5 && role == Qt::BackgroundRole )
  18. {
  19.  
  20. return QVariant( Qt::yellow );
  21. }
  22. else if ( index.row() == m_highRow && index.column()== 5 && role == Qt::BackgroundRole )
  23. {
  24. return QVariant( Qt::red );
  25. }
  26. else
  27. {
  28. return QSortFilterProxyModel::data( index, role );
  29. }
  30.  
  31.  
  32. }
  33. void MyProxyModel::getRows( int rowHigh,int rowLow)
  34. {
  35. m_highRow=rowHigh;
  36. m_lowRow=rowLow;
  37. }
To copy to clipboard, switch view to plain text mode 

So how do I get the proper data to be highlighted after the table is sorted?