[PyKDE] Searching in a list of strings

Fredrik Juhlin laz at strakt.com
Thu May 30 11:25:00 BST 2002


On Thu, 2002-05-30 at 09:13, Janos Blazi wrote:
> I have a QListView containing up to 100,000 entries. Now I should like
> to implement some sort of search: The strings in the list view should be
> compared against an entered user string and only those strings in the
> list view, that contain the user string, should be shown.
> 
> How can I do this?
> 
> I thought, I should create an QListViewItemIterator and looking at the
> items in the QListView. But then, if I do the comparing in Python, I
> shall have to convert the QStrings back to Python strings and that will
> be very, very slow.
> Any hints, how to do this *as fast as possible*?
QListView::findItem() should do the trick:

QListViewItem * QListView::findItem ( const QString & text, int column,
ComparisonFlags compare = ExactMatch | CaseSensitive ) const 

Finds the first list view item in column column, that matches text and
returns the item, or returns 0 of no such item could be found. Pass
OR-ed together Qt::StringComparisonMode values in the compare flag, to
control how the matching is performed. The default comparison mode is
case-sensitive, exact match. 

//Fredrik




More information about the PyQt mailing list