1.创建一个字符串列表作为补全数据源
QStringList wordlist; wordlist<< "apple" <<"banana" << "orange";
2.将QCompleter的数据源设置为之前创建的QStringList,与QLineEdit控件关联
QCompleter * completer = new QCompleter(wordlist,this); completer->setMaxVisibleItems(6); //设置最大显示为6行,超过出现滚动条 completer->setCaseSensitivity(Qt::CaseInsensitive); //大小写不敏感 ui->lineEditName->setCompleter(completer);
3.自定义QCompleter下拉补全列表的样式
QAbstractItemView* popup = completer->popup(); popup->setFont(QFont("Times New Roman", 13)); popup->setStyleSheet("color: black; background-color: rgb(220, 233, 239);");
标签:completion,box,popup,wordlist,补全,QCompleter,completer,Qt From: https://www.cnblogs.com/gnos1s/p/18145272