Important: Please read the Qt Code of Conduct -

How to find a letter in full word by using QCompleter for QLineEdit Auto Completion?

  • Hi...

    I have a QLineEdit, I have to set the auto completion for the QLineEdit, So i tried it using QCompleter. I have a QStringList of 5 items in it (eg. America, Africa, Canada, England, France ). The QCompleter's auto completion is based on the Prefix (first character) of the String List.

    Suppose if i type "C" in the QLineEdit, then only Canada is suggested by the QCompleter.

    But i want to display all the items which has the Character "C" in the string list. That is, my suggestion list should look like, America, Africa, Canada and France. which has the character C in it. How to find the Letter in a full word by using QCompleter?.
    Or is there any other ways of doing it? Please give your suggestions.

    @#include <QLineEdit>
    #include <QCompleter>

    LECompleter::LECompleter(QWidget *parent) :
    ui(new Ui::LECompleter)

    QStringList wordList;
    wordList << "America" << "Africa" << "Canada" << "England" <<"France";
    QLineEdit *lineEdit = new QLineEdit(this);
    QCompleter *completer = new QCompleter(wordList,this);


    delete ui;

    Thanks & Regards

  • What you want is very similar to "this":

  • Custom completer seems to be the best way. I hope this thread will be helpful:

Log in to reply