PDA

View Full Version : Searching in a list.



kaushal_gaurav
14th October 2008, 06:55
Hi,

I have a search box and a list of items (QStrings). I want to implement search logic where in when some thing is typed in the search box then list is updated accordingly.

My question is that... is there some support provided by QT for this or i have to reinvent the wheel myself?

If yes.. then please provide some code clips....

Help.....

Regards,
GK

spirit
14th October 2008, 07:50
if I understood properly then you can use QComboBox whith set property
void setEditable ( bool editable ) editable == true. this property allow to add entered values in QComboBox immediately by pressing Enter.

aamer4yu
14th October 2008, 07:52
What are you using to display the data ??
If you are using QListWidget, then u have 2 ways -
1. Use QListWidget::findItems and fill the list widget with new data.
2. Do a linear traversal on all the items and hide the items that dont match the search string.

If you are using model/view, then probably QSortFilterProxyModel will do the work for you. :)

montylee
14th October 2008, 14:26
if I understood properly then you can use QComboBox whith set property
void setEditable ( bool editable ) editable == true. this property allow to add entered values in QComboBox immediately by pressing Enter.
The items are added only temporarily to the combo box, so you'll have to save it somewhere. Otherwise when you restart your application again, you won't get the same items.

setEditable works well though, i have used it in my code.

If you are using a line edit for getting input data and adding items to a internal list, you have to use list iterator to search for duplicate items in the list and then add the items to the list.

kaushal_gaurav
15th October 2008, 09:00
The problem has nothing to do with ComboBox...
I have followed the approach suggested by aamer4yu
1. Use QListWidget::findItems and fill the list widget with new data.

Thanks every one .... Good day...