Solved text edit completer
-
i'm looking at this example as a reference for me to write a completer for
QPlainTextEdit
subclass:
http://doc.qt.io/qt-5/qtwidgets-tools-customcompleter-example.htmlhowever, 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?
-
Hi
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.
-
@mrjj
okay, but in my case i need it. -
@user4592357
hi
You are free to call comple() at any moment. so its more up to you to trigger it.
maybe on keypress will do it. -
@mrjj
i call it. i do it as in example. but in my case there are spaces in between the words, and i was selecting bytext_cursor.select(QTextCursor::WordUnderCursor)
. changed that to text_cursor.select(QTextCursor::LineUnderCursor), now works! -
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 docompleter->model()->sort(0)
explicitly. i don't think i should've done that, right?i mean, just
setModelSorting()
should've done the job:
from docs:This property holds the way the model is sorted
-
@user4592357 said in text edit completer:
setModelSorting
Hi
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.