PYQT5(3-3)QCompleter实现自动联想

    def init_lineedit(self,items_list):
        # 增加自动补全
        a=[]
        for i in items_list:
            print(i['code'])
            a.append(i['code'])
        self.completer = QCompleter(a)
        # 设置匹配模式  有三种: Qt.MatchStartsWith 开头匹配(默认)  Qt.MatchContains 内容匹配  Qt.MatchEndsWith 结尾匹配
        self.completer.setFilterMode(Qt.MatchContains)
        # 设置补全模式  有三种: QCompleter.PopupCompletion(默认)QCompleter.InlineCompletion   QCompleter.UnfilteredPopupCompletion
        self.completer.setCompletionMode(QCompleter.PopupCompletion)
        # 给lineedit设置补全器
        self.pid_edit.setCompleter(self.completer)

你可能感兴趣的:(PYQT5(3-3)QCompleter实现自动联想)