Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to filter QListView

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleCompatibility
Platform(s):
Symbian
Article
Created: rahul.kulshreshtha (07 Oct 2010)
Last edited: hamishwillee (23 Jul 2012)

Steps:

1. Create a model that will hold all data and fill it

   QStandardItemModel model;
   for (char i = 'A'; i <= 'Z'; ++i) {
       model.appendRow(new QStandardItem(QString("Item %1").arg(i)));
   }

2. Create a proxy model which will be used to filter list.

   QSortFilterProxyModel proxyModel;

3. Link model and proxy model

   proxyModel.setSourceModel(&model);

4. Create a QListView

   QListView list;

5. Link proxy model and list view and show UI

   list.setModel(&proxyModel);
   list.show();

6. Apply filter

   QRegExp regExp("*R*", Qt::CaseInsensitive, QRegExp::Wildcard);
   proxyModel.setFilterRegExp(regExp);

This will automatically update QListView. See the example for more details and SIGNAL handling. File:QListViewExample.zip

Special thanks to divanov and mkfnx for their contribution in thread http://www.developer.nokia.com/Community/Discussion/showthread.php?210848-How-to-fiter-a-list

This page was last modified on 23 July 2012, at 12:41.
123 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×