Results 1 to 4 of 4

Thread: Combobox entries filter as I type

  1. #1
    Join Date
    Jul 2009
    Location
    Jordan, and UAE
    Posts
    55
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Combobox entries filter as I type

    Hello everyone

    I have a large data-set that I populate to a combo box, what I would like to do, is to filter the results of that set as I type, so if i type something like Hello, all the entries that contains the word "hello", would only appear in the combo box

    How to do this thing with combo-box and is using a combo box the best method to implement this? or if you think some other method is more appropriate, I would love to hear about it!

    any suggestions are most welcomed!

    thanks for your help!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Combobox entries filter as I type

    You could use a normal QLineEdit with a QCompleter.

  3. #3
    Join Date
    Jul 2009
    Location
    Jordan, and UAE
    Posts
    55
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Combobox entries filter as I type

    Thanks Lykurg

    but I also want the user to be able to see all the entries, is that possible with the QLineEdit?

    thanks

  4. #4
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Combobox entries filter as I type

    You can use a QSortFilterProxyModel Something like:
    Qt Code:
    1.  
    2. for (int x = 0; x < 1000; x++)
    3. {
    4. model->insertRow(model->rowCount());
    5. model->setData(model->index(model->rowCount() - 1, 0), QString("hello%1").arg(x), Qt::DisplayRole);
    6. }
    7.  
    8. QComboBox * cb = new QComboBox;
    9.  
    10. proxy->setSourceModel(model);
    11.  
    12. cb->setModel(proxy);
    13. cb->setEditable(true);
    14. cb->setCompleter(0);
    15.  
    16. // When the edit text changes, use it to filter the proxy model.
    17. connect(cb, SIGNAL(editTextChanged(QString)), proxy, SLOT(setFilterWildcard(QString)));
    To copy to clipboard, switch view to plain text mode 

  5. The following 2 users say thank you to numbat for this useful post:

    alizadeh91 (29th April 2013), yazwas (9th August 2009)

Similar Threads

  1. Convert between a custom data type wrapped in a QVariant
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 09:07
  2. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  3. Template classes and abstraction of type
    By Raistlin in forum General Programming
    Replies: 15
    Last Post: 1st April 2008, 10:18
  4. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38

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.