How to accomplish drop down word suggestions in Qt?

懵懂的女人 提交于 2019-12-18 13:25:35

问题


Say I have 10 names in a QListWidget (which is hidden) and an a QLineEdit. Now if I type the letter "a" in the line Edit it should display a drop down of all those name in the list widget that begin with the letter "A". the user could select using a mouse or a keyboard (since there will be a vertical scroll-bar). I am not sure if a QLineEdit could do this. But I would like to know what is out there to accomplish this.


回答1:


You can use QCompleter which provides a way for autocompletion in widgets like QLineEdit and QComboBox. When the user starts typing a word, QCompleter suggests possible ways of completing the word, based on a word list.

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);


来源:https://stackoverflow.com/questions/24248606/how-to-accomplish-drop-down-word-suggestions-in-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!