Hi All,

I want to implement a filter for QTreeView.

Qt Code:
  1. -Apple
  2. |____ Object_01
  3. |____ Object_02
  4. |____ XYZ
  5. -Banana
  6. |____ Object_03
  7. |____ Lemon
  8. - Orange
  9. |____ Rabbit
  10. |____ Object_04
  11. |____ Object_05
To copy to clipboard, switch view to plain text mode 

I have to use a LineEdit for dynamic filter. (Connection to textchange I have done)
Conditions:
1> With every Stroke of letter whole tree should be filtered.
e.g. If in lineEdit I say Obj it should show, important thing is every word in the list should start with Obj.

Qt Code:
  1. -Apple
  2. |____ Object_01
  3. |____ Object_02
  4. -Banana
  5. |____ Object_03
  6. - Orange
  7. |____ Object_04
  8. |____ Object_05
To copy to clipboard, switch view to plain text mode 


I tried using simple filter example(BasisSortFilter) it works perfectly fine for tree with only parents and no children. However it's not working with tree with childrens (above example)
This quote I read while going through the documentation of qsortfilterproxymodel.
For hierarchical models, the filter is applied recursively to all children. If a parent item doesn't match the filter, none of its children will be shown.

This slot is connected to lineEdit with

Qt Code:
  1. connect(FilterLineEdit, SIGNAL(textChanged(QString)),this, SLOT(filterChanged()));
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void FilterDialog::filterChanged()
  2. {
  3. QRegExp::PatternSyntax syntax = QRegExp::RegExp;
  4. Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive;
  5. QString strPattern = "^" + FilterLineEdit->text();
  6. QRegExp regExp(strPattern, caseSensitivity);
  7. proxyModel->setFilterRegExp(regExp);
  8. }
To copy to clipboard, switch view to plain text mode 

Thanks in advance.