继承者: QFontComboBox
def
addItem
(icon, text[, userData=None])
def
addItem
(text[, userData=None])
def
addItems
(texts)
def
autoCompletion
()
def
completer
()
def
count
()
def
currentData
([role=Qt.UserRole])
def
currentIndex
()
def
currentText
()
def
duplicatesEnabled
()
def
findData
(data[, role=Qt.UserRole[, flags=static_cast<Qt.MatchFlags>(Qt.MatchExactly|Qt.MatchCaseSensitive)]])
def
findText
(text[, flags=static_cast<Qt.MatchFlags>(Qt.MatchExactly|Qt.MatchCaseSensitive)])
def
hasFrame
()
def
iconSize
()
def
initStyleOption
(option)
def
inputMethodQuery
(query, argument)
def
insertItem
(index, icon, text[, userData=None])
def
insertItem
(index, text[, userData=None])
def
insertItems
(index, texts)
def
insertPolicy
()
def
insertSeparator
(index)
def
isEditable
()
def
itemData
(index[, role=Qt.UserRole])
def
itemDelegate
()
def
itemIcon
(index)
def
itemText
(index)
def
lineEdit
()
def
maxCount
()
def
maxVisibleItems
()
def
minimumContentsLength
()
def
model
()
def
modelColumn
()
def
placeholderText
()
def
removeItem
(index)
def
rootModelIndex
()
def
setAutoCompletion
(enable)
def
setAutoCompletionCaseSensitivity
(sensitivity)
def
setCompleter
(c)
def
setDuplicatesEnabled
(enable)
def
setEditable
(editable)
def
setFrame
(arg__1)
def
setIconSize
(size)
def
setInsertPolicy
(policy)
def
setItemData
(index, value[, role=Qt.UserRole])
def
setItemDelegate
(delegate)
def
setItemIcon
(index, icon)
def
setItemText
(index, text)
def
setLineEdit
(edit)
def
setMaxCount
(max)
def
setMaxVisibleItems
(maxItems)
def
setMinimumContentsLength
(characters)
def
setModel
(model)
def
setModelColumn
(visibleColumn)
def
setPlaceholderText
(placeholderText)
def
setRootModelIndex
(index)
def
setSizeAdjustPolicy
(policy)
def
setValidator
(v)
def
setView
(itemView)
def
sizeAdjustPolicy
()
def
validator
()
def
view
()
def
clear
()
def
clearEditText
()
def
setCurrentIndex
(index)
def
setCurrentText
(text)
def
setEditText
(text)
def
activated
(arg__1)
def
activated
(index)
def
currentIndexChanged
(arg__1)
def
currentIndexChanged
(index)
def
currentTextChanged
(arg__1)
def
editTextChanged
(arg__1)
def
highlighted
(arg__1)
def
highlighted
(index)
def
textActivated
(arg__1)
def
textHighlighted
(arg__1)
![]()
A
QComboBoxprovides a means of presenting a list of options to the user in a way that takes up the minimum amount of screen space.组合框是显示当前项的选择 Widget,且可以弹出可选择项的列表。组合框可能是可编辑的,使用户能够修改每列表项。
组合框可以包含像素图及字符串;
insertItem()andsetItemText()functions are suitably overloaded. For editable comboboxes, the functionclearEditText()is provided, to clear the displayed string without changing the combobox’s contents.会发射 3 个信号若组合框当前项改变,
currentIndexChanged(),currentTextChanged()andactivated().currentIndexChanged()andcurrentTextChanged()are always emitted regardless if the change was done programmatically or by user interaction, whileactivated()is only emitted when the change is caused by user interaction. Thehighlighted()signal is emitted when the user highlights an item in the combobox popup list. All three signals exist in two versions, one with aQString自变量和一个带有int自变量。若用户选择或突显像素图,仅int信号被发射。每当可编辑组合框文本改变时editTextChanged()信号被发射。当用户在可编辑组合框中录入新字符串时,可能插入或可能不插入 Widget,且可以将 Widget 插入在多个位置。默认策略是
InsertAtBottom但可以改变这使用setInsertPolicy().可以将输入约束到可编辑组合框使用
QValidator;见setValidator(). By default, any input is accepted.可以使用插入函数填充组合框,
insertItem()andinsertItems()for example. Items can be changed withsetItemText(). An item can be removed withremoveItem()and all items can be removed withclear(). The text of the current item is returned bycurrentText(), and the text of a numbered item is returned with text(). The current item can be set withsetCurrentIndex(). The number of items in the combobox is returned bycount(); the maximum number of items can be set withsetMaxCount(). You can allow editing usingsetEditable(). For editable comboboxes you can set auto-completion usingsetCompleter()and whether or not the user can add duplicates is set withsetDuplicatesEnabled().
QComboBox使用 模型/视图框架 用于其弹出列表并存储其项。默认情况下QStandardItemModel存储项和QListView子类显示弹出列表。可以直接访问模型和视图 (采用model()andview()), butQComboBoxalso provides functions to set and get item data (e.g.,setItemData()anditemText()). You can also set a new model and view (withsetModel()andsetView()). For the text and icon in the combobox label, the data in the model that has theDisplayRoleandDecorationRole在使用。注意:不可以更改SelectionMode的view(), e.g., by usingsetSelectionMode().
QComboBox
(
[
parent=None
]
)
¶
- param parent
构造组合框采用给定
parent
,使用默认模型
QStandardItemModel
.
PySide2.QtWidgets.QComboBox.
InsertPolicy
¶
此枚举指定什么是
QComboBox
应该做的,当用户键入新字符串时。
|
常量 |
描述 |
|---|---|
|
QComboBox.NoInsert |
字符串不会插入组合框。 |
|
QComboBox.InsertAtTop |
字符串将插入作为第一组合框项。 |
|
QComboBox.InsertAtCurrent |
当前项将 replaced 通过字符串。 |
|
QComboBox.InsertAtBottom |
将字符串插入在组合框最后项之后。 |
|
QComboBox.InsertAfterCurrent |
将字符串插入在组合框当前项之后。 |
|
QComboBox.InsertBeforeCurrent |
将字符串插入在组合框当前项之前。 |
|
QComboBox.InsertAlphabetically |
按字母次序将字符串插入组合框。 |
PySide2.QtWidgets.QComboBox.
SizeAdjustPolicy
¶
此枚举指定尺寸提示应如何
QComboBox
调节当添加新内容或改变内容时。
|
常量 |
描述 |
|---|---|
|
QComboBox.AdjustToContents |
组合框始终根据内容调节 |
|
QComboBox.AdjustToContentsOnFirstShow |
组合框将调节到其首次展示内容。 |
|
QComboBox.AdjustToMinimumContentsLengthWithIcon |
组合框将调节到
|
PySide2.QtWidgets.QComboBox.
activated
(
arg__1
)
¶
arg__1 – unicode
注意
此函数被弃用。
PySide2.QtWidgets.QComboBox.
activated
(
index
)
¶
index
–
int
PySide2.QtWidgets.QComboBox.
addItem
(
icon
,
text
[
,
userData=None
]
)
¶
icon
–
QIcon
text – unicode
userData – object
把项添加到组合框,采用给定
icon
and
text
,和包含指定
userData
(存储在
UserRole
)。项会被追加到现有项列表。
PySide2.QtWidgets.QComboBox.
addItem
(
text
[
,
userData=None
]
)
¶
text – unicode
userData – object
把项添加到组合框,采用给定
text
,和包含指定
userData
(存储在
UserRole
)。项会被追加到现有项列表。
PySide2.QtWidgets.QComboBox.
addItems
(
texts
)
¶
texts – 字符串列表
添加每字符串在给定
texts
到组合框。每项会被依次追加到现有项列表中。
PySide2.QtWidgets.QComboBox.
autoCompletion
(
)
¶
bool
注意
此函数被弃用。
使用
completer()
代替。
另请参阅
PySide2.QtWidgets.QComboBox.
autoCompletionCaseSensitivity
(
)
¶
CaseSensitivity
注意
此函数被弃用。
使用
setCompleter()
and
setCaseSensitivity()
代替。
PySide2.QtWidgets.QComboBox.
clear
(
)
¶
清零组合框,移除所有项。
注意:若组合框有设置外部模型,此模型仍会被清零 (当调用此函数时)。
PySide2.QtWidgets.QComboBox.
clearEditText
(
)
¶
清零用于在组合框中编辑的行编辑内容。
PySide2.QtWidgets.QComboBox.
completer
(
)
¶
返回被用于自动补全组合框文本输入的补全器。
另请参阅
setCompleter()
editable
PySide2.QtWidgets.QComboBox.
count
(
)
¶
int
PySide2.QtWidgets.QComboBox.
currentData
(
[
role=Qt.UserRole
]
)
¶
role
–
int
object
PySide2.QtWidgets.QComboBox.
currentIndex
(
)
¶
int
另请参阅
PySide2.QtWidgets.QComboBox.
currentIndexChanged
(
arg__1
)
¶
arg__1 – unicode
注意
此函数被弃用。
PySide2.QtWidgets.QComboBox.
currentIndexChanged
(
index
)
¶
index
–
int
PySide2.QtWidgets.QComboBox.
currentText
(
)
¶
unicode
另请参阅
PySide2.QtWidgets.QComboBox.
currentTextChanged
(
arg__1
)
¶
arg__1 – unicode
PySide2.QtWidgets.QComboBox.
duplicatesEnabled
(
)
¶
bool
PySide2.QtWidgets.QComboBox.
editTextChanged
(
arg__1
)
¶
arg__1 – unicode
PySide2.QtWidgets.QComboBox.
findData
(
data
[
,
role=Qt.UserRole
[
,
flags=static_cast<Qt.MatchFlags>(Qt.MatchExactly|Qt.MatchCaseSensitive)
]
]
)
¶
data – object
role
–
int
flags
–
MatchFlags
int
返回索引当项包含给定
data
为给定
role
;否则返回 -1。
flags
指定如何搜索组合框项。
PySide2.QtWidgets.QComboBox.
findText
(
text
[
,
flags=static_cast<Qt.MatchFlags>(Qt.MatchExactly|Qt.MatchCaseSensitive)
]
)
¶
text – unicode
flags
–
MatchFlags
int
返回索引当项包含给定
text
;否则返回 -1。
flags
指定如何搜索组合框项。
PySide2.QtWidgets.QComboBox.
hasFrame
(
)
¶
bool
PySide2.QtWidgets.QComboBox.
hidePopup
(
)
¶
Hides the list of items in the combobox if it is currently visible and resets the internal state, so that if the custom pop-up was shown inside the reimplemented
showPopup()
, then you also need to reimplement the function to hide your custom pop-up and call the base class implementation to reset the internal state whenever your custom pop-up widget is hidden.
另请参阅
PySide2.QtWidgets.QComboBox.
highlighted
(
arg__1
)
¶
arg__1 – unicode
注意
此函数被弃用。
PySide2.QtWidgets.QComboBox.
highlighted
(
index
)
¶
index
–
int
PySide2.QtWidgets.QComboBox.
iconSize
(
)
¶
QSize
另请参阅
PySide2.QtWidgets.QComboBox.
initStyleOption
(
option
)
¶
option
–
QStyleOptionComboBox
初始化
option
采用值来自此
QComboBox
。此方法对子类是有用的,当需要
QStyleOptionComboBox
, but don’t want to fill in all the information themselves.
另请参阅
PySide2.QtWidgets.QComboBox.
inputMethodQuery
(
query
,
argument
)
¶
query
–
InputMethodQuery
argument – object
object
PySide2.QtWidgets.QComboBox.
insertItem
(
index
,
icon
,
text
[
,
userData=None
]
)
¶
index
–
int
icon
–
QIcon
text – unicode
userData – object
插入
icon
,
text
and
userData
(存储在
UserRole
) 进组合框在给定
index
.
If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.
另请参阅
PySide2.QtWidgets.QComboBox.
insertItem
(
index
,
text
[
,
userData=None
]
)
¶
index
–
int
text – unicode
userData – object
插入
text
and
userData
(存储在
UserRole
) 进组合框在给定
index
.
If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.
另请参阅
PySide2.QtWidgets.QComboBox.
insertItems
(
index
,
texts
)
¶
index
–
int
texts – 字符串列表
插入字符串从
list
到组合框作为单独项,起始于
index
指定。
If the index is equal to or higher than the total number of items, the new items are appended to the list of existing items. If the index is zero or negative, the new items are prepended to the list of existing items.
另请参阅
PySide2.QtWidgets.QComboBox.
insertPolicy
(
)
¶
另请参阅
PySide2.QtWidgets.QComboBox.
insertSeparator
(
index
)
¶
index
–
int
将分隔符项插入组合框在给定
index
.
If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.
另请参阅
PySide2.QtWidgets.QComboBox.
isEditable
(
)
¶
bool
PySide2.QtWidgets.QComboBox.
itemData
(
index
[
,
role=Qt.UserRole
]
)
¶
index
–
int
role
–
int
object
返回数据为给定
role
以给定
index
in the combobox, or
Invalid
若此角色没有数据。
另请参阅
PySide2.QtWidgets.QComboBox.
itemDelegate
(
)
¶
返回由弹出列表视图使用的项委托。
另请参阅
PySide2.QtWidgets.QComboBox.
itemIcon
(
index
)
¶
index
–
int
QIcon
返回图标为给定
index
在组合框。
另请参阅
PySide2.QtWidgets.QComboBox.
itemText
(
index
)
¶
index
–
int
unicode
返回文本为给定
index
在组合框。
另请参阅
PySide2.QtWidgets.QComboBox.
lineEdit
(
)
¶
返回用于编辑组合框项的行编辑,若
None
若没有行编辑。
仅可编辑组合框拥有行编辑。
另请参阅
PySide2.QtWidgets.QComboBox.
maxCount
(
)
¶
int
另请参阅
PySide2.QtWidgets.QComboBox.
maxVisibleItems
(
)
¶
int
另请参阅
PySide2.QtWidgets.QComboBox.
minimumContentsLength
(
)
¶
int
PySide2.QtWidgets.QComboBox.
model
(
)
¶
QAbstractItemModel
返回由组合框使用的模型。
另请参阅
PySide2.QtWidgets.QComboBox.
modelColumn
(
)
¶
int
另请参阅
PySide2.QtWidgets.QComboBox.
placeholderText
(
)
¶
unicode
另请参阅
PySide2.QtWidgets.QComboBox.
removeItem
(
index
)
¶
index
–
int
移除项位于给定
index
从组合框。这将更新当前索引,若索引被移除。
此函数什么都不做,若
index
超出范围。
PySide2.QtWidgets.QComboBox.
rootModelIndex
(
)
¶
QModelIndex
返回组合框项的根模型项索引。
另请参阅
PySide2.QtWidgets.QComboBox.
setAutoCompletion
(
enable
)
¶
enable
–
bool
注意
此函数被弃用。
使用
setCompleter()
代替。
另请参阅
PySide2.QtWidgets.QComboBox.
setAutoCompletionCaseSensitivity
(
sensitivity
)
¶
sensitivity
–
CaseSensitivity
注意
此函数被弃用。
使用
setCompleter()
and
setCaseSensitivity()
代替。
PySide2.QtWidgets.QComboBox.
setCompleter
(
c
)
¶
c
–
QCompleter
设置
completer
以使用而不是当前补全器。若
completer
is
None
,自动补全被禁用。
默认情况下,对于可编辑组合框,
QCompleter
自动创建不区分大小写的内联补全。
注意
补全器被移除,当
editable
特性变为
false
。设置补全器在
QComboBox
(不可编辑) 会被忽略。
另请参阅
PySide2.QtWidgets.QComboBox.
setCurrentIndex
(
index
)
¶
index
–
int
另请参阅
PySide2.QtWidgets.QComboBox.
setCurrentText
(
text
)
¶
text – unicode
另请参阅
PySide2.QtWidgets.QComboBox.
setDuplicatesEnabled
(
enable
)
¶
enable
–
bool
另请参阅
PySide2.QtWidgets.QComboBox.
setEditText
(
text
)
¶
text – unicode
设置
text
in the combobox’s text edit.
PySide2.QtWidgets.QComboBox.
setEditable
(
editable
)
¶
editable
–
bool
另请参阅
PySide2.QtWidgets.QComboBox.
setFrame
(
arg__1
)
¶
arg__1
–
bool
另请参阅
PySide2.QtWidgets.QComboBox.
setIconSize
(
size
)
¶
size
–
QSize
另请参阅
PySide2.QtWidgets.QComboBox.
setInsertPolicy
(
policy
)
¶
policy
–
InsertPolicy
另请参阅
PySide2.QtWidgets.QComboBox.
setItemData
(
index
,
value
[
,
role=Qt.UserRole
]
)
¶
index
–
int
value – object
role
–
int
设置数据
role
为项在给定
index
在组合框到指定
value
.
另请参阅
PySide2.QtWidgets.QComboBox.
setItemDelegate
(
delegate
)
¶
delegate
–
QAbstractItemDelegate
设置项
delegate
为弹出列表视图。组合框拥有委托的所有权。
警告
You should not share the same instance of a delegate between comboboxes, widget mappers or views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the
closeEditor()
signal, and attempt to access, modify or close an editor that has already been closed.
另请参阅
PySide2.QtWidgets.QComboBox.
setItemIcon
(
index
,
icon
)
¶
index
–
int
icon
–
QIcon
设置
icon
为项在给定
index
在组合框。
另请参阅
PySide2.QtWidgets.QComboBox.
setItemText
(
index
,
text
)
¶
index
–
int
text – unicode
设置
text
为项在给定
index
在组合框。
另请参阅
PySide2.QtWidgets.QComboBox.
setLineEdit
(
edit
)
¶
edit
–
QLineEdit
设置行
edit
以代替使用当前行编辑 Widget。
组合框拥有行编辑的所有权。
另请参阅
PySide2.QtWidgets.QComboBox.
setMaxCount
(
max
)
¶
max
–
int
另请参阅
PySide2.QtWidgets.QComboBox.
setMaxVisibleItems
(
maxItems
)
¶
maxItems
–
int
另请参阅
PySide2.QtWidgets.QComboBox.
setMinimumContentsLength
(
characters
)
¶
characters
–
int
PySide2.QtWidgets.QComboBox.
setModel
(
model
)
¶
model
–
QAbstractItemModel
把模型设置为
model
.
model
必须不是
None
。若希望清零模型的内容,调用
clear()
.
PySide2.QtWidgets.QComboBox.
setModelColumn
(
visibleColumn
)
¶
visibleColumn
–
int
另请参阅
PySide2.QtWidgets.QComboBox.
setPlaceholderText
(
placeholderText
)
¶
placeholderText – unicode
另请参阅
PySide2.QtWidgets.QComboBox.
setRootModelIndex
(
index
)
¶
index
–
QModelIndex
设置根模型项
index
为组合框项。
另请参阅
PySide2.QtWidgets.QComboBox.
setSizeAdjustPolicy
(
policy
)
¶
policy
–
SizeAdjustPolicy
另请参阅
PySide2.QtWidgets.QComboBox.
setValidator
(
v
)
¶
v
–
QValidator
设置
validator
以代替当前使用的验证器。
注意
验证器被移除,当
editable
特性变为
false
.
另请参阅
PySide2.QtWidgets.QComboBox.
setView
(
itemView
)
¶
itemView
–
QAbstractItemView
将组合框弹出所用视图设为给定
itemView
。组合框拥有视图的所有权。
注意:若想要使用方便视图 (像
QListWidget
,
QTableWidget
or
QTreeWidget
),确保调用
setModel()
on the combobox with the convenience widgets model before calling this function.
另请参阅
PySide2.QtWidgets.QComboBox.
showPopup
(
)
¶
显示组合框项列表。若列表为空,就不会展示项。
若重新实现此函数以展示自定义弹出,确保调用
hidePopup()
to reset the internal state.
另请参阅
PySide2.QtWidgets.QComboBox.
sizeAdjustPolicy
(
)
¶
PySide2.QtWidgets.QComboBox.
textActivated
(
arg__1
)
¶
arg__1 – unicode
PySide2.QtWidgets.QComboBox.
textHighlighted
(
arg__1
)
¶
arg__1 – unicode
PySide2.QtWidgets.QComboBox.
validator
(
)
¶
QValidator
返回用于约束组合框文本输入的验证器。
另请参阅
setValidator()
editable
PySide2.QtWidgets.QComboBox.
view
(
)
¶
返回用于组合框弹出的列表视图。
另请参阅