【发布时间】:2016-01-17 13:39:54
【问题描述】:
有一个名为 customSortFilterProxyModel 的类继承自 QSortFilterProxyModel。并且一个受保护的函数 filterAcceptsRow 被覆盖。 但是,根本不调用 filterAcceptsRow。有什么问题? 谢谢。 customSortFilterProxyModel.h
class customSortFilterProxyModel: public QSortFilterProxyModel
{
Q_OBJECT
public:
customSortFilterProxyModel(QObject *parent);
~customSortFilterProxyModel();
protected:
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
};
//customSortFilterProxyModel.cpp
customSortFilterProxyModel::customSortFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
customSortFilterProxyModel::~customSortFilterProxyModel()
{
}
bool customSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
return true;
}
使用此代理模型测试代码
QStringListModel *newModel = new QStringListModel;
QStringList strList;
strList << "1" << "2" << "3" << "4";
newModel->setStringList(strList);
customSortFilterProxyModel *m_customSortFilterProxyModel = new customSortFilterProxyModel(this);
m_customSortFilterProxyModel->setSourceModel(newModel);
【问题讨论】:
标签: c++ windows qt qsortfilterproxymodel