2015-10-19 47 views
2

有一個名爲customSortFilterProxyModel的類繼承自QSortFilterProxyModel。並且一個保護函數filterAcceptsRow是覆蓋。 但是,filterAcceptsRow根本不被調用。會是什麼? 謝謝。使用這種代理模型爲什麼filterAcceptsRow從QSortFilterProxyModel繼承時不被調用?

QStringListModel *newModel = new QStringListModel; 
    QStringList strList; 
    strList << "1" << "2" << "3" << "4"; 
newModel->setStringList(strList); 
    customSortFilterProxyModel *m_customSortFilterProxyModel = new customSortFilterProxyModel(this); 
     m_customSortFilterProxyModel->setSourceModel(newModel); 

回答

0

呼叫此功能進行排序列

m_customSortFilterProxyModel-> 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; 
} 

測試代碼排序(0);

0

我強制我的customSortFilterProxyModel重新加載源模型 setSourceModel。有用。但我不確定這是否是正確的解決方案?

相關問題