AutoComplete using two QStringList

195 Views Asked by At

I know how to use QCompleter class. code:

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

QLineEdit *lineEdit = new QLineEdit(this);

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

But I want to join QString like xxxxx.yyyyy when I type xx all the auto completion from that QStringlist should appear drop down, so after I select the appropriate ones, if I enter . auto completion form 2nd QStringList should drop down.

I know I have not put across my point properly, but it is really tough to explain this.

1

There are 1 best solutions below

0
On

A basic idea which came to my mind is that you should register a key press listener on that QLineEdit which only listens for . character. Once user has entered a . character you should prepend all characters have been entered so far to the second QStringList and feet it to the QCompleter.

Steps:

  • Apply the first QStringList.
  • When user typed ., prepend what has been entered so far to the second QStringList and apply it to the QCompleter.