Add custom list to QCompleter and force it to show it



  • That's the thing, I have a custom list of strings in a database, for example:

    "String123"
    "ThisIsAString"
    "Hello"

    Now, I have my QLineEdit with its QCompleter, so every time my QLineEdit's text change I search in a database for strings containing it. This is:

    I write "Str"
    And the result of my search is a QStringList containing:

    "String123"
    "ThisIsAString"

    Note that it's NOT a "starts with" search. So far so good.

    Now, I want my QComplete to show them as possible options for my QLineEdit.

    1. This is what I DONT want:

      • Attach the database to the QCompleter
      • Write "Str"
      • QCompleter shows "String123"
    1. This is what I DO want:

      • Search in database for "*Str*"
      • Write the resulted QStringList to the QCompleter
      • Show all QCompleter options
      • QCompleter shows "String123" and "ThisIsAString"

    I have been trying and trying but I cant reach the last 3 steps of 2.


  • Lifetime Qt Champion

    Hi,

    Do you mean a combo using e.g. QStringListModel that you set on your QCompleter and that you feed with a QStringList built from your database query output ?



  • @SGaist Yes, more or less that's what Im looking for, but Im not able to figure out how to do it :s


  • Lifetime Qt Champion

    Which part ?



  • I manage to do it :D

    Anyway I think I was a little poor in my reply. The part of connecting the list to the QCompleter was fine, I already did that. The problem was this:

    What I wrote:

    "Chicke"

    What my list had:

    "Chicken"
    "Dogs & Chickens"
    "Ducks, Dogs & Chickens"

    What my QCompleter will show:

    "Chicken"

    What I wanted it to show:

    "Chicken"
    "Dogs & Chickens"
    "Ducks, Dogs & Chickens"

    The only thing I had to do is:

    QCompleter::setCompletionMode(QCompleter::UnfilteredPopupCompletion);

    :D



  • @SGaist But when I tried it, I noticed you cant just press the arrow down/up key to select the text, is there an easy way to do it? Or I will have to write my own class using QCompleter ?


  • Lifetime Qt Champion

    What do you mean by your can't just press the arrow ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.