Friday 17 July 2020

QCompleter and QLineEdit for multiple words

Is there any way to have the QCompleter to act like an autocomplete for multiple words?

Someone has any idea how to do it?


Answers:


I don't 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 then you get the completion "alpha and beta" which is more than one word. There is no limit.

Update after clarifications:

Seems that what is requested is starting a new autocompletion after a delimiter value. In the current case this delimiter will be a space. An equivalent example would be the tree model completer from the Qt examples. This example illustrates how to solve the same situation.


Answers:


No comments:

Post a Comment