×
Namespaces

Variants
Actions

Archived:QListView with a find pane

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.

Article Metadata
Code ExampleTested with
Devices(s): Nokia E71
Compatibility
Platform(s): S60 3rd Edition, FP2
Symbian
S60 3rd Edition FP2
Article
Keywords: QListView, Find pane
Created: User:Technical writer 1 (09 Apr 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

This article explains how to implement a listbox with a find pane similar to the S60 find pane.

Description

Unlike in S60, there is no explicit support for attaching a listbox to a search pane. However, as a workaround you can use QListView and QTextEdit widgets to implement a similar control.

Solution

Whenever text is entered into QTextEdit, you need to filter the QListView model and set the model with the string that contains the entered texts.

QListViewFindPane.cpp

The class QListViewFindPane is derived from QWidget. Ui.textEdit is the text edit widget and ui.listView is the list view widget. filterList() is the private slot which is used to filter the list view model.

 QListViewFindPane::QListViewFindPane(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
//connect the textChanged() signal to filterList()
connect(ui.textEdit,SIGNAL(textChanged()),SLOT(filterList()));
//Filling up the List view with some dummy data
QStringListModel* localModel = new QStringListModel();
QStringList strList;
strList.append("test images");
strList.append("nokia s60 help");
strList.append("no posts only for testing");
strList.append("test blogs");
strList.append("testing never stops");
strList.append("having fun");
strList.append("you live to die another day");
localModel->setStringList(strList);
ui.listView->setModel(localModel);
iModel = new QStringListModel();
//Getting the model of the List view
iModel = static_cast<QStringListModel*> (ui.listView->model());
ui.listView->setFocus();
}
//Private slot
void QListViewFindPane::filterList()
{
//Getting the text entered into the QTextEdit
QString text(ui.textEdit->toPlainText());
//New model to be set
QStringListModel* newmodel = new QStringListModel();
//The original model’s stringList
QStringList strList(iModel->stringList());
QStringList newstrList;
//Filtering the model
for(int i=0;i<iModel->rowCount();i++)
{
if(strList.at(i).contains(text))
{
newstrList.append(strList[i]);
}
}
newmodel->setStringList(newstrList);
//Set the filtered model to the list view
ui.listView->setModel(newmodel);
ui.listView->show();
}


Sample application

File:QListViewFindPane.zip

This page was last modified on 11 October 2012, at 04:14.
59 page views in the last 30 days.