February 12, 2012

Ruzik Ruzik
Lab Rat
293 posts

[Solved]QSortFilterProxyModel dont find in the “folder”

 

Hellow!
I use this code:

  1.  searchModel.setSourceModel(itemModel);
  2.  connect(searchLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(findInModel(const QString&)));

  1. void RizekFaster::findInModel(const QString& str)
  2. {
  3.  if(str.isEmpty())
  4.  {
  5.   dataTreeView->setModel(itemModel);
  6.   return;
  7.  }
  8.  searchModel.setFilterWildcard(str);
  9.  dataTreeView->setModel(&searchModel);
  10. }

But my sort model dont find items in “folders”, it find only items which have not parents
For example:
This is my program with all item in my item model
1
And it is my program with QSortFilterProxyModel
2
How can i do that my sort model find all items?
And other question:
How can i do that my QSortFilterProxyModel find items in all columns simultaneously?
In advance many thank for your help!

5 replies

February 13, 2012

luisvaldes88 luisvaldes88
Lab Rat
31 posts

Hi,

Did you try

  1. QSortFilterProxyModel::setFilterKeyColumn(int)

?

filterKeyColumn : int

This property holds the column where the key used to filter the contents of the source model is read from.
The default value is 0. If the value is -1, the keys will be read from all columns.

By default it is only searching in the column 0

  1. void RizekFaster::findInModel(const QString& str)
  2. {
  3.  if(str.isEmpty())
  4.  {
  5.   dataTreeView->setModel(itemModel);
  6.   return;
  7.  }
  8.  searchModel.setFilterWildcard(str);
  9.  searchModel.setFilterKeyColumn(-1); /*this solves*/
  10.  dataTreeView->setModel(&searchModel);
  11. }

 Signature 

Muchos quieren, pocos pueden, algunos consiguen.

February 13, 2012

Ruzik Ruzik
Lab Rat
293 posts

I try to do it, but it is only mean that program will found items in difetent columns, but it is dont find in the “folders”(like Friends and My Friends in my screen)

February 20, 2012

Andre Andre
Area 51 Engineer
6031 posts

I wrote a proxy you might use as inspiration. Depending on the size of your model, it might need serious performance enhancements, but it is a start. Check this [developer.qt.nokia.com] topic for details.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

February 20, 2012

Ruzik Ruzik
Lab Rat
293 posts

Thank you for all your help!

February 20, 2012

luisvaldes88 luisvaldes88
Lab Rat
31 posts

Andre wrote:
I wrote a proxy you might use as inspiration. Depending on the size of your model, it might need serious performance enhancements, but it is a start. Check this [developer.qt.nokia.com] topic for details.

Great information.
Thanks.

 Signature 

Muchos quieren, pocos pueden, algunos consiguen.

 
  ‹‹ Speed of gif      Login code ››

You must log in to post a reply. Not a member yet? Register here!