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?
#ifndef CUSTOMSORTFILTERPROXYMODEL_H
#define CUSTOMSORTFILTERPROXYMODEL_H
#include <QObject>
#include <QSortFilterProxyModel>
#include <QDebug>
{
Q_OBJECT
enum Column {
Title,
Authors,
ReleaseDate,
About,
Format,
Image
};
public:
CustomSortFilterProxyModel();
~CustomSortFilterProxyModel();
protected:
private:
QList< Column > selectedColumns;
};
#endif // CUSTOMSORTFILTERPROXYMODEL_H
#ifndef CUSTOMSORTFILTERPROXYMODEL_H
#define CUSTOMSORTFILTERPROXYMODEL_H
#include <QObject>
#include <QSortFilterProxyModel>
#include <QDebug>
class CustomSortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
enum Column {
Title,
Authors,
ReleaseDate,
About,
Format,
Image
};
public:
CustomSortFilterProxyModel();
~CustomSortFilterProxyModel();
protected:
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
private:
QList< Column > selectedColumns;
};
#endif // CUSTOMSORTFILTERPROXYMODEL_H
To copy to clipboard, switch view to plain text mode
#include "customsortfilterproxymodel.h"
CustomSortFilterProxyModel::CustomSortFilterProxyModel()
{
}
CustomSortFilterProxyModel::~CustomSortFilterProxyModel()
{
}
{
// never called, why?
qDebug()<< "Custom Sort Filter Proxy Model :: lessThan";
qDebug()<< "colums size: " << selectedColumns.size();
return false;
}
#include "customsortfilterproxymodel.h"
CustomSortFilterProxyModel::CustomSortFilterProxyModel()
{
}
CustomSortFilterProxyModel::~CustomSortFilterProxyModel()
{
}
bool CustomSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
// never called, why?
qDebug()<< "Custom Sort Filter Proxy Model :: lessThan";
qDebug()<< "colums size: " << selectedColumns.size();
return false;
}
To copy to clipboard, switch view to plain text mode
and in mainwindow
proxyModel.setSourceModel( &customTableModel );
ui->tableView->setModel( &proxyModel );
proxyModel.setSourceModel( &customTableModel );
ui->tableView->setModel( &proxyModel );
To copy to clipboard, switch view to plain text mode
Bookmarks