Results 1 to 5 of 5

Thread: Searching in a list.

  1. #1
    Join Date
    Jun 2008
    Posts
    89
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Searching in a list.

    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

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Searching in a list.

    if I understood properly then you can use QComboBox whith set property
    Qt Code:
    1. void setEditable ( bool editable )
    To copy to clipboard, switch view to plain text mode 
    editable == true. this property allow to add entered values in QComboBox immediately by pressing Enter.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Searching in a list.

    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.

  4. #4
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Searching in a list.

    Quote Originally Posted by spirit View Post
    if I understood properly then you can use QComboBox whith set property
    Qt Code:
    1. void setEditable ( bool editable )
    To copy to clipboard, switch view to plain text mode 
    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.

  5. #5
    Join Date
    Jun 2008
    Posts
    89
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Searching in a list.

    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...

Similar Threads

  1. Replies: 2
    Last Post: 19th September 2008, 06:21
  2. Single slot for multiple list boxes
    By Sheetal in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2008, 07:53
  3. Replies: 1
    Last Post: 22nd October 2007, 03:04
  4. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 20:25
  5. Replies: 26
    Last Post: 21st July 2007, 22:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.