QLineEdit按键Tab键时显⽰历史记录#LineEdit添加历史记录功能,按下回车添加⾄历史中
class LineEditWithHistory(QtWidgets.QLineEdit):
def__init__(self, parent ,inputList=[]):
super(LineEditWithHistory, self).__init__(parent)
#⽤于存放历史记录的List
七夕是几月几日2022年self.inputList = inputList
#LineEdit设置QCompleter,⽤于显⽰历史记录
selfpleter = QtWidgets.QCompleter(self)
self.listModel = QtCore.QStringListModel(self.inputList, self)
头像国旗selfpleter.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
selfpleter.setModel(self.listModel)
t(self.Slot_completer_activated)有关国庆节的黑板报
self.setCompleter(selfpleter)
#输⼊完成按下回车后去重添加到历史记录中
牧童骑黄牛
def Slot_editingFinished(self):
content = ()
if content != "":
if content not in self.inputList:
self.inputList.append(content)
self.listModel.setStringList(self.inputList)
赵树海老婆selfpleter.setCompletionMode(QtWidgets.QCompleter.PopupCompletion)
#按下回车后恢复显⽰模式 doc.qt.io/qt-5/qcompleter.html#activated
def Slot_completer_activated(self,text):
selfpleter.setCompletionMode(QtWidgets.QCompleter.PopupCompletion)
def event(self, event):
#按下Tab键时弹出所有记录
pe() == QtCore.QEvent.KeyPress and event.key() == QtCore.Qt.Key_Tab:
#设置不过滤显⽰ doc.qt.io/qt-5/qcompleter.html#completionMode-prop
selfpleter.setCompletionMode(QtWidgets.QCompleter.UnfilteredPopupCompletion)
selfpleterplete()
selfpleter.popup().show()
梦到坐电梯return True
return super().event(event)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论