Hi,
I have a subclass QSortFilterProxyModel with custom lessThan function to provide sort by specific columns but this function is never called. Maybe You know why?


Qt Code:
  1. #ifndef CUSTOMSORTFILTERPROXYMODEL_H
  2. #define CUSTOMSORTFILTERPROXYMODEL_H
  3.  
  4. #include <QObject>
  5. #include <QSortFilterProxyModel>
  6. #include <QDebug>
  7.  
  8. class CustomSortFilterProxyModel : public QSortFilterProxyModel
  9. {
  10. Q_OBJECT
  11.  
  12. enum Column {
  13. Title,
  14. Authors,
  15. ReleaseDate,
  16. About,
  17. Format,
  18. Image
  19. };
  20.  
  21. public:
  22. CustomSortFilterProxyModel();
  23. ~CustomSortFilterProxyModel();
  24.  
  25. protected:
  26. bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
  27.  
  28. private:
  29. QList< Column > selectedColumns;
  30. };
  31.  
  32. #endif // CUSTOMSORTFILTERPROXYMODEL_H
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "customsortfilterproxymodel.h"
  2.  
  3. CustomSortFilterProxyModel::CustomSortFilterProxyModel()
  4. {
  5.  
  6. }
  7.  
  8. CustomSortFilterProxyModel::~CustomSortFilterProxyModel()
  9. {
  10.  
  11. }
  12.  
  13. bool CustomSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
  14. {
  15. // never called, why?
  16. qDebug()<< "Custom Sort Filter Proxy Model :: lessThan";
  17. qDebug()<< "colums size: " << selectedColumns.size();
  18.  
  19. return false;
  20. }
To copy to clipboard, switch view to plain text mode 

and in mainwindow
Qt Code:
  1. proxyModel.setSourceModel( &customTableModel );
  2. ui->tableView->setModel( &proxyModel );
To copy to clipboard, switch view to plain text mode