How to execute drop-down sentences of words in Qt?

Let's say I have 10 names in a QListWidget (which is hidden) and a QLineEdit . Now, if I type the letter "a" in the "Edit" line, it should display a drop-down list of all these names in the list widgets that start with the letter "A". the user can select using the mouse or keyboard (as there will be a vertical scroll bar). I'm not sure what QLineEdit can do. But I would like to know what is there for this.

+6
source share
1 answer

You can use QCompleter which provides an autocomplete method in widgets such as QLineEdit and QComboBox . When a user begins to enter a word, QCompleter offers possible ways to complete a word based on a list of words.

An example from the Qt documentation :

 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); 
+20
source

Source: https://habr.com/ru/post/970903/


All Articles