Qt 5.3.0 & 5.3.1 Linux
I've subclassed QSortFilterProxyModel and implemented lessThan(). When someone clicks the tableview header (which Ive 'connect'ed to) and I call invalidate(), I see it call 'lessThan' but the tableview never updates. Can someone tell me what Im missing? lessThan() is definitely sorting things properly as I put some print statements to see what was happening inside there when it was called. I've also tried adding table->repaint() which doesn't do anything.
Here's my code:
QTableView *table = m_ui->tableView;
table->resize(930, 200);
table->setAlternatingRowColors(true);
table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->verticalHeader()->hide();
QStringList header;
header << "ID";
header << "Prefix";
header << "First";
header << "M";
header << "Last";
int cols = header.size();
BookcaseModel *bookcaseModel = new BookcaseModel(this, cols, header);
m_proxy_bookcase = new SortFilterProxyModelBookcase(this);
m_proxy_bookcase->setSourceModel(bookcaseModel);
m_proxy_bookcase->sort(0, Qt::AscendingOrder);
m_proxy_bookcase->setDynamicSortFilter(true);
m_proxy_bookcase->setSortRole(Qt::DisplayRole);
table->setModel(bookcaseModel);
table->setSortingEnabled(true);
table->horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
table->horizontalHeader()->setSectionsClickable(true);
connect(table->horizontalHeader(), SIGNAL(sectionClicked(int)),
this, SLOT(selectedColumnSlot(int)));
Then the slot:
void selectedColumnSlot(int col)
{
m_proxy_bookcase->sort(col, Qt::DescendingOrder);
m_proxy_bookcase->invalidate();
}