|
10Qter豆
下图是我想要的效果,具体效果如下(其实就是Visual Studio解决方案上方搜索框的效果)
1.如果子节点无匹配项 父节点也不匹配,则父子节点都不显示
2.如果任一子节点匹配,父节点不匹配,父节点也要显示
3.如果只有父节点匹配,所有子节点不匹配,则只显示父节点
我现在的效果是父节点一直在显示,其它正常,如何实现上述效果呢
网上看到一篇帖子说可以这样做,但是当逐字符清空搜索框里的搜索条件时,无法正常显示
- // \reimp
- bool MyFilterProxyModel::filterAcceptsRow ( int source_row,
- const QModelIndex & source_parent ) const
- {
- 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;
- }
复制代码
希望做过的给点建议
|
|