QCompleter and QLineEdit for a few words

Is there a way to make QCompleter act as autocomplete for a few words?

Does anyone have any idea how to do this?

thanks

+3
source share
1 answer

I do not know if I understand correctly:

QStringList wordList;
wordList << "alpha and beta" << "omega" << "omicron" << "zeta";

QCompleter *completer = new QCompleter(wordList, this);
completer->setCaseSensitivity(Qt::CaseInsensitive);

QLineEdit *lineEdit = new QLineEdit(this);
lineEdit->setCompleter(completer);

If you type alp, you will end up with "alpha and beta" that contains more than one word. No limit.

Update after clarification:

It seems that a new autocomplete is requested to start after the delimiter value. In the current case, this delimiter will be space. An equivalent example is the detailed tree model from Qt examples. This example illustrates how to solve the same situation.

+8

All Articles