本文整理汇总了Python中PyQt5.QtWidgets.QCompleter.setCompletionPrefix方法的典型用法代码示例。如果您正苦于以下问题:Python QCompleter.setCompletionPrefix方法的具体用法?Python QCompleter.setCompletionPrefix怎么用?Python QCompleter.setCompletionPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QCompleter
的用法示例。
在下文中一共展示了QCompleter.setCompletionPrefix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Completer
# 需要导入模块: from PyQt5.QtWidgets import QCompleter [as 别名]
# 或者: from PyQt5.QtWidgets.QCompleter import setCompletionPrefix [as 别名]
class Completer(QGraphicsProxyWidget, object):
''' Class for handling text autocompletion in the SDL scene '''
def __init__(self, parent):
''' Create an autocompletion list popup '''
widget = QListWidget()
super(Completer, self).__init__(parent)
self.setWidget(widget)
self.string_list = QStringListModel()
self._completer = QCompleter()
self.parent = parent
self._completer.setCaseSensitivity(Qt.CaseInsensitive)
# For some reason the default minimum size is (61,61)
# Set it to 0 so that the size of the box is not taken
# into account when it is hidden.
self.setMinimumSize(0, 0)
self.prepareGeometryChange()
self.resize(0, 0)
self.hide()
def set_completer_list(self):
''' Set list of items for the autocompleter popup '''
compl = [item.replace('-', '_') for item in
self.parent.parentItem().completion_list]
self.string_list.setStringList(compl)
self._completer.setModel(self.string_list)
def set_completion_prefix(self, completion_prefix):
'''
Set the current completion prefix (user-entered text)
and set the corresponding list of words in the popup widget
'''
self._completer.setCompletionPrefix(completion_prefix)
self.widget().clear()
count = self._completer.completionCount()
for i in xrange(count):
self._completer.setCurrentRow(i)
self.widget().addItem(self._completer.currentCompletion())
self.prepareGeometryChange()
if count:
self.resize(self.widget().sizeHintForColumn(0) + 40, 70)
else:
self.resize(0, 0)
return count
# pylint: disable=C0103
def keyPressEvent(self, e):
super(Completer, self).keyPressEvent(e)
if e.key() == Qt.Key_Escape:
self.parentItem().setFocus()
# Consume the event so that it is not repeated at EditableText level
e.accept()
# pylint: disable=C0103
def focusOutEvent(self, event):
''' When the user leaves the popup, return focus to parent '''
super(Completer, self).focusOutEvent(event)
self.hide()
self.resize(0, 0)
self.parentItem().setFocus()
示例2: HelpWebSearchWidget
# 需要导入模块: from PyQt5.QtWidgets import QCompleter [as 别名]
# 或者: from PyQt5.QtWidgets.QCompleter import setCompletionPrefix [as 别名]
#.........这里部分代码省略.........
def __completerHighlighted(self, index):
"""
Private slot handling the highlighting of an entry of the completer.
@param index index of the item (QModelIndex)
@return flah indicating a successful highlighting (boolean)
"""
if self.__suggestionsItem and \
self.__suggestionsItem.index().row() == index.row():
return False
if self.__recentSearchesItem and \
self.__recentSearchesItem.index().row() == index.row():
return False
self.setText(index.data())
return True
def __textEdited(self, txt):
"""
Private slot to handle changes of the search text.
@param txt search text (string)
"""
if self.__suggestionsEnabled:
if self.__suggestTimer is None:
self.__suggestTimer = QTimer(self)
self.__suggestTimer.setSingleShot(True)
self.__suggestTimer.setInterval(200)
self.__suggestTimer.timeout.connect(self.__getSuggestions)
self.__suggestTimer.start()
else:
self.__completer.setCompletionPrefix(txt)
self.__completer.complete()
def __getSuggestions(self):
"""
Private slot to get search suggestions from the configured search
engine.
"""
searchText = self.text()
if searchText:
self.__openSearchManager.currentEngine()\
.requestSuggestions(searchText)
def __newSuggestions(self, suggestions):
"""
Private slot to receive a new list of suggestions.
@param suggestions list of suggestions (list of strings)
"""
self.__suggestions = suggestions
self.__setupCompleterMenu()
self.__completer.complete()
def __showEnginesMenu(self):
"""
Private slot to handle the display of the engines menu.
"""
self.__enginesMenu.clear()
from .OpenSearch.OpenSearchEngineAction import OpenSearchEngineAction
engineNames = self.__openSearchManager.allEnginesNames()
for engineName in engineNames:
engine = self.__openSearchManager.engine(engineName)