本文整理汇总了Python中PyQt4.QtGui.QStringListModel.setParent方法的典型用法代码示例。如果您正苦于以下问题:Python QStringListModel.setParent方法的具体用法?Python QStringListModel.setParent怎么用?Python QStringListModel.setParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QStringListModel
的用法示例。
在下文中一共展示了QStringListModel.setParent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LineEdit_Autocomplete
# 需要导入模块: from PyQt4.QtGui import QStringListModel [as 别名]
# 或者: from PyQt4.QtGui.QStringListModel import setParent [as 别名]
class LineEdit_Autocomplete(QLineEdit):
AutoComplete = pyqtSignal(QString)
def __init__(self, *args, **kwargs):
QLineEdit.__init__(self, *args, **kwargs)
self.completions = [] # All available completions
self.googlesuggestions = [] # This will be filled automatically if GOOGLESEARCH is True
self.partials = [] # Parsed completions according to partially typed word
self.staticsuggestions = [] # Static suggestions list
self.cursorpos = 0
self.wordstart = -1 # Start of word where cursor positioned
self.wordend = -1 # End of word where cursor is positioned
self.lastindex = -1 # Last used completion of available completions
######################## Completer for first part (without trigger)
self.completer = QCompleter()
self.completer.setParent(self)
self.completer.setCaseSensitivity(Qt.CaseInsensitive)
self.completer.popup().setMinimumHeight(40) # Keep a minumum heigt if the completer is shown
self.setCompleter(self.completer)
self.model = QStringListModel()
self.model.setParent(self.completer)
self.completer.setModel(self.model)
self.completer.setMaxVisibleItems(6)
self.__set_data(self.model)
self.setCompletionDialogFoam() # Set to standard (PopupCompletion)
self.setKeyWordForCompletion() # default keyword = "whitespace" - " "
self.Timer = QTimer() # Setup singleshot Timer for GoogleSuggestions
self.Timer.setSingleShot(True)
self.setGOOGLESEARCH_attr = False # initial Settings
self.languageForGOOGLESEARCH = "en"
self.textEdited.connect(self.onTextEdit) # define connections
self.Timer.timeout.connect(self.googlesearch)
self.toolButton = None
def set_data(self):
"""
:Triggers the internal __set_data Methode
"""
self.__set_data(self.model)
def __set_data(self, model):
"""
:param model: QStringlistmodel which is used
:Is adding all suggestions which are available at the time of call to the model which manage the input
for the used completer (Popup, Inline or Unfiltered Popup Completion
"""
#print("Setup Completer with available completions")
stringlist = []
for item in self.staticsuggestions:
stringlist.append(item)
for item in self.googlesuggestions:
stringlist.append(item)
model.setStringList(stringlist)
def setCompletionDialogFoam(self, QCompleter_Mode=QCompleter.PopupCompletion):
'''
Possible Options: QCompleter.UnfilteredPopupCompletion
QCompleter.PopupCompletion
QCompleter.InlineCompletion
'''
self.completer.setCompletionMode(QCompleter_Mode)
def setGOOGLESEARCH(self, bool):
'''
With this attribute the "google-suggest" function can be activated, and deactivated....
'''
self.setGOOGLESEARCH_attr = bool
def setLanguageForGOOGLESEARCH(self, language="en"):
self.languageForGOOGLESEARCH = language
@pyqtSlot(QString)
def onTextEdit(self, Text=None):
'''
If Googelsearch is set to "True" this will trigger the suggestions after 500ms, when the user do not enter
anything.
'''
if self.setGOOGLESEARCH_attr:
self.Timer.start(500)
# Timer is connected to "googlesearch"
#.........这里部分代码省略.........