bool filter = QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
if (filter)
{
return true;
}
else
{
// check all decendant's
QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent);
for (int k=0; k<sourceModel()->rowCount(source_index); k++)
{
if (filterAcceptsRow(k, source_index))
{
return true;
}
}
}
return false;
运行结果可以实现对整个treeview实现过滤,但无法对单个节点下的内容进行过滤
bool filter = QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
if (filter)
return true;
QModelIndex current_index = mapToSource(treeView->currentIndex());
QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent);
while (source_index.isValid() && source_index != current_index)
source_index = source_index.parent();
return source_index != current_index;