pyqt5 lineEdit自动补全
输入框自动联想,直接上代码
# 联想列表
list =['python','c','java']
def auto_lineEdi():
"""
自动补全函数
"""
# 设置匹配模式 有三种: Qt.MatchStartsWith 开头匹配(默认)
# Qt.MatchContains 内容匹配
# Qt.MatchEndsWith 结尾匹配
self.completer = QtWidgets.QCompleter(list)
self.completer.setFilterMode(Qt.MatchContains)
# 设置补全模式 有三种: QCompleter.PopupCompletion 弹出选项补全(默认)
# QCompleter.InlineCompletion 行内显示补全
# QCompleter.UnfilteredPopupCompletion 全显选项补全
self.completer.setCompletionMode(QtWidgets.QCompleter.PopupCompletion)
# 设置 lineEdit的补全器
self.lineEdit.setCompleter(self.completer)