Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Implement smart search in qcombobox
Forum Updated to NodeBB v4.3 + New Features

Implement smart search in qcombobox

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 414 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcus Barnet
    wrote on last edited by
    #1

    Hi to all,

    I use to load the name and the surname of a list of users into a qcombobox.

    model.setQuery("SELECT * FROM utente ");
    
       for (int i = 0; i < model.rowCount(); ++i) {
         ui->listautenti->addItem(model.record(i).value("nome").toString() + " " + model.record(i).value("cognome").toString() + " #" + model.record(i).value("id").toString());
    
       }
    

    the qcombobox is editable and I can select items by typing the first letter of the user's name.
    However, I would like to be able to implement some kind of smart search in order to select all the items that match what I write inside the combobox.

    For example, if I write:

    "jack"

    the following items should be proposed:
    Jack Moss
    Michael Jackson
    Pierce Jackssen

    and so on.

    It is possible to do something like that in Qt?

    JonBJ 1 Reply Last reply
    0
    • M Marcus Barnet

      Hi to all,

      I use to load the name and the surname of a list of users into a qcombobox.

      model.setQuery("SELECT * FROM utente ");
      
         for (int i = 0; i < model.rowCount(); ++i) {
           ui->listautenti->addItem(model.record(i).value("nome").toString() + " " + model.record(i).value("cognome").toString() + " #" + model.record(i).value("id").toString());
      
         }
      

      the qcombobox is editable and I can select items by typing the first letter of the user's name.
      However, I would like to be able to implement some kind of smart search in order to select all the items that match what I write inside the combobox.

      For example, if I write:

      "jack"

      the following items should be proposed:
      Jack Moss
      Michael Jackson
      Pierce Jackssen

      and so on.

      It is possible to do something like that in Qt?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Marcus-Barnet
      I don't know whether you can use a standalone QComboBox for this --- doubtless you can write some dedicated code perhaps to accomplish it --- but are you aware of Qt's QCompleter Class for just this?

      You can use QCompleter to provide auto completions in any Qt widget, such as QLineEdit and QComboBox. When the user starts typing a word, QCompleter suggests possible ways of completing the word, based on a word list. The word list is provided as a QAbstractItemModel. (For simple applications, where the word list is static, you can pass a QStringList to QCompleter's constructor.)

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved