text edit completer
i'm looking at this example as a reference for me to write a completer for
however, it only shows autocompletion on some shortcut press. what i wanna do is, it to behave like a normal auto completion, i.e. filter suggestion list based on what already typed.
i can think of updating the model with every key press but i think that's a heavy operation. any better solution?
That is the normal operation. (guess on type)
QStringList wordList; wordList << "alpha" << "omega" << "omicron" << "zeta"; QCompleter *completer = new QCompleter(wordList, this); completer->setCaseSensitivity(Qt::CaseInsensitive); ui->lineEdit->setCompleter(completer);
Guess as soon as you write. However for a TextEdit that might be annoying and hence i thinks that's why sample uses shortcut.
okay, but in my case i need it.
You are free to call comple() at any moment. so its more up to you to trigger it.
maybe on keypress will do it.
i call it. i do it as in example. but in my case there are spaces in between the words, and i was selecting by
text_cursor.select(QTextCursor::WordUnderCursor). changed that to text_cursor.select(QTextCursor::LineUnderCursor), now works!
user4592357 last edited by user4592357
there's also something else: as in the example, i applied
setModelSorting(QCompleter::CaseSensitivelySortedModel)to the completer. however, it wasn't sorted, and i had to do
completer->model()->sort(0)explicitly. i don't think i should've done that, right?
i mean, just
setModelSorting()should've done the job:
This property holds the way the model is sorted
As far as i know its only for hinting the sort order. setting it wont
tell model to sort. Its more like a clue for completer.