Bojan
9th March 2006, 02:59
What's the most proper way of sorting a QTableView? QSortFilterProxyModel doesn't seem to work on QTableViews. At least I can't get it to work. For example if I take the sorting treeview example, and just change it so there is a QTableView, it doesn't work:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFile file(":/default.txt");
file.open(QIODevice::ReadOnly);
TreeModel model(file.readAll());
file.close();
QSortFilterProxyModel sortingModel;
sortingModel.setSourceModel(&model);
QTableView sortedView;
sortedView.setModel(&sortingModel);
sortedView.setWindowTitle("Sorted Data");
sortedView.setSelectionBehavior(QAbstractItemView: :SelectRows);
sortedView.horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
sortedView.horizontalHeader()->setSortIndicatorShown(true);
sortedView.horizontalHeader()->setClickable(true);
sortedView.verticalHeader()->setVisible(false);
sortedView.show();
return app.exec();
}
I would like to be able to sort the rows based on the column data in the clicked column. Qt 4.1. I don't need sample source code, just description of what to do, what things to connect, etc... Any advice is much appreciated.
Bojan
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFile file(":/default.txt");
file.open(QIODevice::ReadOnly);
TreeModel model(file.readAll());
file.close();
QSortFilterProxyModel sortingModel;
sortingModel.setSourceModel(&model);
QTableView sortedView;
sortedView.setModel(&sortingModel);
sortedView.setWindowTitle("Sorted Data");
sortedView.setSelectionBehavior(QAbstractItemView: :SelectRows);
sortedView.horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
sortedView.horizontalHeader()->setSortIndicatorShown(true);
sortedView.horizontalHeader()->setClickable(true);
sortedView.verticalHeader()->setVisible(false);
sortedView.show();
return app.exec();
}
I would like to be able to sort the rows based on the column data in the clicked column. Qt 4.1. I don't need sample source code, just description of what to do, what things to connect, etc... Any advice is much appreciated.
Bojan