私は最初の列(index0)に基づいて階層的なフィルタQTreeView
をフィルタリングする動作フィルタ機能(filterAcceptsRow
)を持っています。ユーザーがトラフ(フィルタリングされた)QTreeView
を検索できるように、検索を接続する必要があります。QLineEdit
この関数に検索アルゴリズムを追加する方法がわかりません。誰かが私を理解するのを助けることができますか?検索アルゴリズムは、すべての5つの列(index0-index4)でQString
を検索する必要があります。Qt(C++)でトラフa(フィルタリングされた)QSortFilterProxyModelを検索するには?
マイフィルタ機能:
bool ProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
QModelIndex index3 = sourceModel()->index(sourceRow, 3, sourceParent);
QModelIndex index4 = sourceModel()->index(sourceRow, 4, sourceParent);
if (m_filterEnabled)
{
foreach (const QString &row, rows)
{
if (sourceModel()->data(index0).toString().contains(row) && m_shownRow)
return true; //element should be shown
else if (sourceModel()->data(index0).toString().contains(row) && !m_shownRow)
return false; //element should NOT be shown
}
if (m_shownRow)
return false;
else
return true;
} else {
return true; //no filter -> show everything
}
}
ありがとうございました、これは私の問題を解決しました! :) – Engo