本文整理汇总了Python中PyQt5.QtWidgets.QCompleter.setWidget方法的典型用法代码示例。如果您正苦于以下问题:Python QCompleter.setWidget方法的具体用法?Python QCompleter.setWidget怎么用?Python QCompleter.setWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QCompleter
的用法示例。
在下文中一共展示了QCompleter.setWidget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HelpWebSearchWidget
# 需要导入模块: from PyQt5.QtWidgets import QCompleter [as 别名]
# 或者: from PyQt5.QtWidgets.QCompleter import setWidget [as 别名]
class HelpWebSearchWidget(E5ClearableLineEdit):
"""
Class implementing a web search widget for the web browser.
@signal search(QUrl) emitted when the search should be done
"""
search = pyqtSignal(QUrl)
def __init__(self, parent=None):
"""
Constructor
@param parent reference to the parent widget (QWidget)
"""
super(HelpWebSearchWidget, self).__init__(parent)
from E5Gui.E5LineEdit import E5LineEdit
from E5Gui.E5LineEditButton import E5LineEditButton
from .OpenSearch.OpenSearchManager import OpenSearchManager
self.__mw = parent
self.__openSearchManager = OpenSearchManager(self)
self.__openSearchManager.currentEngineChanged.connect(
self.__currentEngineChanged)
self.__currentEngine = ""
self.__enginesMenu = QMenu(self)
self.__engineButton = E5LineEditButton(self)
self.__engineButton.setMenu(self.__enginesMenu)
self.addWidget(self.__engineButton, E5LineEdit.LeftSide)
self.__searchButton = E5LineEditButton(self)
self.__searchButton.setIcon(UI.PixmapCache.getIcon("webSearch.png"))
self.addWidget(self.__searchButton, E5LineEdit.LeftSide)
self.__model = QStandardItemModel(self)
self.__completer = QCompleter()
self.__completer.setModel(self.__model)
self.__completer.setCompletionMode(
QCompleter.UnfilteredPopupCompletion)
self.__completer.setWidget(self)
self.__searchButton.clicked.connect(self.__searchButtonClicked)
self.textEdited.connect(self.__textEdited)
self.returnPressed.connect(self.__searchNow)
self.__completer.activated[QModelIndex].connect(
self.__completerActivated)
self.__completer.highlighted[QModelIndex].connect(
self.__completerHighlighted)
self.__enginesMenu.aboutToShow.connect(self.__showEnginesMenu)
self.__suggestionsItem = None
self.__suggestions = []
self.__suggestTimer = None
self.__suggestionsEnabled = Preferences.getHelp("WebSearchSuggestions")
self.__recentSearchesItem = None
self.__recentSearches = []
self.__maxSavedSearches = 10
self.__engine = None
self.__loadSearches()
self.__setupCompleterMenu()
self.__currentEngineChanged()
def __searchNow(self):
"""
Private slot to perform the web search.
"""
searchText = self.text()
if not searchText:
return
globalSettings = QWebSettings.globalSettings()
if not globalSettings.testAttribute(
QWebSettings.PrivateBrowsingEnabled):
if searchText in self.__recentSearches:
self.__recentSearches.remove(searchText)
self.__recentSearches.insert(0, searchText)
if len(self.__recentSearches) > self.__maxSavedSearches:
self.__recentSearches = \
self.__recentSearches[:self.__maxSavedSearches]
self.__setupCompleterMenu()
url = self.__openSearchManager.currentEngine().searchUrl(searchText)
self.search.emit(url)
def __setupCompleterMenu(self):
"""
Private method to create the completer menu.
"""
if not self.__suggestions or \
(self.__model.rowCount() > 0 and
self.__model.item(0) != self.__suggestionsItem):
self.__model.clear()
self.__suggestionsItem = None
else:
self.__model.removeRows(1, self.__model.rowCount() - 1)
#.........这里部分代码省略.........