Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QCompleter and QLineEdit for multiple words

Tags:

java

c++

qt

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

Someone has any idea how to do it?

like image 323
mileschet Avatar asked Jan 23 '23 21:01

mileschet


1 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.

like image 101
Yorgos Pagles Avatar answered Feb 01 '23 19:02

Yorgos Pagles