QCompleterclass provides completions based on an item model. 更多 …
def
caseSensitivity
()
def
completionColumn
()
def
completionCount
()
def
completionMode
()
def
completionModel
()
def
completionPrefix
()
def
completionRole
()
def
currentCompletion
()
def
currentIndex
()
def
currentRow
()
def
filterMode
()
def
maxVisibleItems
()
def
model
()
def
modelSorting
()
def
popup
()
def
setCaseSensitivity
(caseSensitivity)
def
setCompletionColumn
(column)
def
setCompletionMode
(mode)
def
setCompletionRole
(role)
def
setCurrentRow
(row)
def
setFilterMode
(filterMode)
def
setMaxVisibleItems
(maxItems)
def
setModel
(c)
def
setModelSorting
(sorting)
def
setPopup
(popup)
def
setWidget
(widget)
def
widget
()
def
wrapAround
()
def
pathFromIndex
(index)
def
splitPath
(path)
def
complete
([rect=QRect()])
def
setCompletionPrefix
(prefix)
def
setWrapAround
(wrap)
def
activated
(index)
def
activated
(text)
def
highlighted
(index)
def
highlighted
(text)
可以使用
QCompleterto provide auto completions in any Qt widget, such asQLineEditandQComboBox. When the user starts typing a word,QCompletersuggests possible ways of completing the word, based on a word list. The word list is provided as aQAbstractItemModel。(对于单词列表是静态的简单应用程序,可以传递QStringListtoQCompleter‘s constructor.)
A
QCompleteris used typically with aQLineEditorQComboBox. For example, here’s how to provide auto completions from a simple word list in aQLineEdit:wordList = ["alpha", "omega", "omicron", "zeta"] lineEdit = QLineEdit(self) completer = QCompleter(wordList, self) completer.setCaseSensitivity(Qt.CaseInsensitive) lineEdit.setCompleter(completer)A
QFileSystemModel可以被用于提供文件名自动补全。例如:completer = QCompleter(self) completer.setModel(QDirModel(completer)) lineEdit.setCompleter(completer)To set the model on which
QCompletershould operate, callsetModel(). By default,QCompleterwill attempt to match thecompletion prefix(即:用户已开始键入的单词) 针对EditRole在区分大小写的模型中存储第 0 列数据。这可以被改变使用setCompletionRole(),setCompletionColumn(),和setCaseSensitivity().若模型按被用于补全的角色和列进行排序,可以调用
setModelSorting()with eitherCaseSensitivelySortedModelorCaseInsensitivelySortedModelas the argument. On large models, this can lead to significant performance improvements, becauseQCompletercan then use binary search instead of linear search. The binary search only works when thefilterModeisMatchStartsWith.模型可以是
list model,table model,或tree model。树模型补全稍微更复杂,且涵盖于Handling Tree 模型以下章节。
completionMode()determines the mode used to provide completions to the user.
要检索单候选字符串,调用
setCompletionPrefix()with the text that needs to be completed and callcurrentCompletion(). You can iterate through the list of completions as below:i = 0 while completer.setCurrentRow(i): print "%s is match number %d" % (completer.currentCompletion(), i) i += 1
completionCount()returns the total number of completions for the current prefix.completionCount()should be avoided when possible, since it requires a scan of the entire model.
completionModel()return a list model that contains all possible completions for the current completion prefix, in the order in which they appear in the model. This model can be used to display the current completions in a custom view. CallingsetCompletionPrefix()automatically refreshes the completion model.
QCompletercan look for completions in tree models, assuming that any item (or sub-item or sub-sub-item) can be unambiguously represented as a string by specifying the path to the item. The completion is then performed one level at a time.Let’s take the example of a user typing in a file system path. The model is a (hierarchical)
QFileSystemModel。补全发生在每路径元素。例如,若当前文本是C:\Wind,QCompletermight suggestWindows去补全当前路径元素。同样,若当前文本是C:\Windows\Sy,QCompletermight suggest系统.For this kind of completion to work,
QCompleterneeds to be able to split the path into a list of strings that are matched at each level. ForC:\Windows\Sy, it needs to be split as “C:”, “Windows” and “Sy”. The default implementation ofsplitPath(), splits thecompletionPrefix使用separator()if the model is aQFileSystemModel.To provide completions,
QCompleterneeds to know the path from an index. This is provided bypathFromIndex(). The default implementation ofpathFromIndex(), returns the data for theedit role的列表模型和绝对文件路径,若模式为QFileSystemModel.
QCompleter
(
model
[
,
parent=None
]
)
¶
QCompleter([parent=None])
QCompleter(completions[, parent=None])
- param parent
QObject- param model
QAbstractItemModel- param completions
字符串列表
构造补全器对象采用给定
parent
提供补全来自指定
model
.
构造补全器对象采用给定
parent
.
PySide2.QtWidgets.QCompleter.
CompletionMode
¶
此枚举指定如何向用户提供补全。
|
常量 |
描述 |
|---|---|
|
QCompleter.PopupCompletion |
当前补全被显示在弹出窗口中。 |
|
QCompleter.InlineCompletion |
补全内联出现 (作为选中文本)。 |
|
QCompleter.UnfilteredPopupCompletion |
所有可能的补全均被显示在弹出窗口中,采用最有可能建议指示作为当前。 |
另请参阅
PySide2.QtWidgets.QCompleter.
ModelSorting
¶
此枚举指定如何对模型项进行排序。
|
常量 |
描述 |
|---|---|
|
QCompleter.UnsortedModel |
模型不排序。 |
|
QCompleter.CaseSensitivelySortedModel |
模型排序区分大小写。 |
|
QCompleter.CaseInsensitivelySortedModel |
模型排序不区分大小写。 |
另请参阅
PySide2.QtWidgets.QCompleter.
activated
(
index
)
¶
index
–
QModelIndex
PySide2.QtWidgets.QCompleter.
activated
(
text
)
¶
text – unicode
PySide2.QtWidgets.QCompleter.
caseSensitivity
(
)
¶
CaseSensitivity
另请参阅
PySide2.QtWidgets.QCompleter.
complete
(
[
rect=QRect()
]
)
¶
rect
–
QRect
For
PopupCompletion
和 QCompletion::UnfilteredPopupCompletion 模式,调用此函数显示当前补全的弹出窗口。默认情况下,若
rect
未指定,弹出窗口显示在底部对于
widget()
。若
rect
被指定,弹出窗口显示在矩形的左边缘。
For
InlineCompletion
模式,
highlighted()
signal is fired with the current completion.
PySide2.QtWidgets.QCompleter.
completionColumn
(
)
¶
int
PySide2.QtWidgets.QCompleter.
completionCount
(
)
¶
int
返回为当前前缀的补全数。对于具有大量项的未排序模型,这可能是昂贵的。使用
setCurrentRow()
and
currentCompletion()
to iterate through all the completions.
PySide2.QtWidgets.QCompleter.
completionMode
(
)
¶
另请参阅
PySide2.QtWidgets.QCompleter.
completionModel
(
)
¶
QAbstractItemModel
返回补全模型。补全模型是包含为当前补全前缀的所有可能匹配的只读列表模型。补全模型被自动更新以反映当前补全。
注意
此函数的返回值被定义为
QAbstractItemModel
纯粹为通用性。这种实际返回的模型是实例对于
QAbstractProxyModel
子类。
另请参阅
PySide2.QtWidgets.QCompleter.
completionPrefix
(
)
¶
unicode
PySide2.QtWidgets.QCompleter.
completionRole
(
)
¶
int
另请参阅
PySide2.QtWidgets.QCompleter.
currentCompletion
(
)
¶
unicode
返回当前补全字符串。这包括
completionPrefix
。当同时使用
setCurrentRow()
, it can be used to iterate through all the matches.
PySide2.QtWidgets.QCompleter.
currentIndex
(
)
¶
QModelIndex
返回当前补全的模型索引在
completionModel()
.
PySide2.QtWidgets.QCompleter.
currentRow
(
)
¶
int
返回当前行。
另请参阅
PySide2.QtWidgets.QCompleter.
filterMode
(
)
¶
MatchFlags
另请参阅
PySide2.QtWidgets.QCompleter.
highlighted
(
index
)
¶
index
–
QModelIndex
PySide2.QtWidgets.QCompleter.
highlighted
(
text
)
¶
text – unicode
PySide2.QtWidgets.QCompleter.
maxVisibleItems
(
)
¶
int
另请参阅
PySide2.QtWidgets.QCompleter.
model
(
)
¶
QAbstractItemModel
返回提供补全字符串的模型。
PySide2.QtWidgets.QCompleter.
modelSorting
(
)
¶
另请参阅
PySide2.QtWidgets.QCompleter.
pathFromIndex
(
index
)
¶
index
–
QModelIndex
unicode
返回路径为给定
index
。补全器对象使用此,以从底层模型中获得补全文本。
默认实现返回
edit
role
的列表模型项。它返回绝对文件路径,若模型是
QFileSystemModel
.
另请参阅
PySide2.QtWidgets.QCompleter.
popup
(
)
¶
返回用于显示补全的弹出窗口。
另请参阅
PySide2.QtWidgets.QCompleter.
setCaseSensitivity
(
caseSensitivity
)
¶
caseSensitivity
–
CaseSensitivity
另请参阅
PySide2.QtWidgets.QCompleter.
setCompletionColumn
(
column
)
¶
column
–
int
另请参阅
PySide2.QtWidgets.QCompleter.
setCompletionMode
(
mode
)
¶
mode
–
CompletionMode
另请参阅
PySide2.QtWidgets.QCompleter.
setCompletionPrefix
(
prefix
)
¶
prefix – unicode
另请参阅
PySide2.QtWidgets.QCompleter.
setCompletionRole
(
role
)
¶
role
–
int
另请参阅
PySide2.QtWidgets.QCompleter.
setCurrentRow
(
row
)
¶
row
–
int
bool
把当前行设为
row
指定。返回
true
若成功;否则返回
false
.
此函数可以被使用沿着
currentCompletion()
to iterate through all the possible completions.
PySide2.QtWidgets.QCompleter.
setFilterMode
(
filterMode
)
¶
filterMode
–
MatchFlags
另请参阅
PySide2.QtWidgets.QCompleter.
setMaxVisibleItems
(
maxItems
)
¶
maxItems
–
int
另请参阅
PySide2.QtWidgets.QCompleter.
setModel
(
c
)
¶
c
–
QAbstractItemModel
把提供补全的模型设为
model
。
model
可以是列表模型 (或树模型)。若模型事先已经被设置,且它有
QCompleter
作为其父级,它将被删除。
为方便起见,若
model
是
QFileSystemModel
,
QCompleter
切换其
caseSensitivity
to
CaseInsensitive
在 Windows 和
CaseSensitive
在其它平台。
另请参阅
completionModel()
modelSorting
Handling
Tree
模型
PySide2.QtWidgets.QCompleter.
setModelSorting
(
sorting
)
¶
sorting
–
ModelSorting
另请参阅
PySide2.QtWidgets.QCompleter.
setPopup
(
popup
)
¶
popup
–
QAbstractItemView
把用于显示补全的弹出窗口设为
popup
.
QCompleter
拥有视图的所有权。
A
QListView
被自动创建当
completionMode()
is set to
PopupCompletion
or
UnfilteredPopupCompletion
。默认弹出窗口显示
completionColumn()
.
Ensure that this function is called before the view settings are modified. This is required since view’s properties may require that a model has been set on the view (for example, hiding columns in the view requires a model to be set on the view).
另请参阅
PySide2.QtWidgets.QCompleter.
setWidget
(
widget
)
¶
widget
–
QWidget
把为其提供补全的小部件设为
widget
。此函数被自动调用当
QCompleter
被设置在
QLineEdit
使用
setCompleter()
or on a
QComboBox
使用
setCompleter()
. The widget needs to be set explicitly when providing completions for custom widgets.
另请参阅
PySide2.QtWidgets.QCompleter.
setWrapAround
(
wrap
)
¶
wrap
–
bool
另请参阅
PySide2.QtWidgets.QCompleter.
splitPath
(
path
)
¶
path – unicode
字符串列表
分割给定
path
成字符串,用于每级匹配在
model()
.
The default implementation of splits a file system path based on
separator()
when the sourceModel() is a
QFileSystemModel
.
当用于列表模型时,返回列表中的第一项被用于匹配。
另请参阅
pathFromIndex()
Handling
Tree
模型
PySide2.QtWidgets.QCompleter.
widget
(
)
¶
返回补全器对象正为其提供补全的 Widget。
另请参阅
PySide2.QtWidgets.QCompleter.
wrapAround
(
)
¶
bool
另请参阅