为什么不调用继承自QSortFilterProxyModel的filterAcceptsRow?

时间:2015-10-19 09:04:40

标签: c++ windows qt qsortfilterproxymodel

有一个名为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);

2 个答案:

答案 0 :(得分:0)

为排序列调用此函数

m_customSortFilterProxyModel-&GT;排序(0);

答案 1 :(得分:0)

我强制我的customSortFilterProxyModel重新加载源模型 setSourceModel。有用。但我不确定这是否是正确的解决方案?