QComboBox

Inheritance diagram of PySide2.QtWidgets.QComboBox

Inherited by: QFontComboBox

Synopsis

Functions

Virtual functions

Slots

Signals

Detailed Description

The PySide2.QtWidgets.QComboBox widget is a combined button and popup list.

../../_images/windows-combobox.png

A PySide2.QtWidgets.QComboBox provides a means of presenting a list of options to the user in a way that takes up the minimum amount of screen space.

A combobox is a selection widget that displays the current item, and can pop up a list of selectable items. A combobox may be editable, allowing the user to modify each item in the list.

Comboboxes can contain pixmaps as well as strings; the PySide2.QtWidgets.QComboBox.insertItem() and PySide2.QtWidgets.QComboBox.setItemText() functions are suitably overloaded. For editable comboboxes, the function PySide2.QtWidgets.QComboBox.clearEditText() is provided, to clear the displayed string without changing the combobox’s contents.

There are two signals emitted if the current item of a combobox changes, PySide2.QtWidgets.QComboBox.currentIndexChanged() and PySide2.QtWidgets.QComboBox.activated() . PySide2.QtWidgets.QComboBox.currentIndexChanged() is always emitted regardless if the change was done programmatically or by user interaction, while PySide2.QtWidgets.QComboBox.activated() is only emitted when the change is caused by user interaction. The PySide2.QtWidgets.QComboBox.highlighted() signal is emitted when the user highlights an item in the combobox popup list. All three signals exist in two versions, one with a PySide2.QtCore.QString argument and one with an int argument. If the user selects or highlights a pixmap, only the int signals are emitted. Whenever the text of an editable combobox is changed the PySide2.QtWidgets.QComboBox.editTextChanged() signal is emitted.

When the user enters a new string in an editable combobox, the widget may or may not insert it, and it can insert it in several locations. The default policy is InsertAtBottom but you can change this using PySide2.QtWidgets.QComboBox.setInsertPolicy() .

It is possible to constrain the input to an editable combobox using PySide2.QtGui.QValidator ; see PySide2.QtWidgets.QComboBox.setValidator() . By default, any input is accepted.

A combobox can be populated using the insert functions, PySide2.QtWidgets.QComboBox.insertItem() and PySide2.QtWidgets.QComboBox.insertItems() for example. Items can be changed with PySide2.QtWidgets.QComboBox.setItemText() . An item can be removed with PySide2.QtWidgets.QComboBox.removeItem() and all items can be removed with PySide2.QtWidgets.QComboBox.clear() . The text of the current item is returned by PySide2.QtWidgets.QComboBox.currentText() , and the text of a numbered item is returned with text(). The current item can be set with PySide2.QtWidgets.QComboBox.setCurrentIndex() . The number of items in the combobox is returned by PySide2.QtWidgets.QComboBox.count() ; the maximum number of items can be set with PySide2.QtWidgets.QComboBox.setMaxCount() . You can allow editing using PySide2.QtWidgets.QComboBox.setEditable() . For editable comboboxes you can set auto-completion using PySide2.QtWidgets.QComboBox.setCompleter() and whether or not the user can add duplicates is set with PySide2.QtWidgets.QComboBox.setDuplicatesEnabled() .

PySide2.QtWidgets.QComboBox uses the model/view framework for its popup list and to store its items. By default a PySide2.QtGui.QStandardItemModel stores the items and a PySide2.QtWidgets.QListView subclass displays the popuplist. You can access the model and view directly (with PySide2.QtWidgets.QComboBox.model() and PySide2.QtWidgets.QComboBox.view() ), but PySide2.QtWidgets.QComboBox also provides functions to set and get item data (e.g., PySide2.QtWidgets.QComboBox.setItemData() and PySide2.QtWidgets.QComboBox.itemText() ). You can also set a new model and view (with PySide2.QtWidgets.QComboBox.setModel() and PySide2.QtWidgets.QComboBox.setView() ). For the text and icon in the combobox label, the data in the model that has the Qt.DisplayRole and Qt.DecorationRole is used. Note that you cannot alter the QAbstractItemView.SelectionMode of the PySide2.QtWidgets.QComboBox.view() , e.g., by using PySide2.QtWidgets.QAbstractItemView.setSelectionMode() .

class PySide2.QtWidgets.QComboBox([parent=nullptr])
Parameters:parentPySide2.QtWidgets.QWidget

Constructs a combobox with the given parent , using the default model PySide2.QtGui.QStandardItemModel .

PySide2.QtWidgets.QComboBox.InsertPolicy

This enum specifies what the PySide2.QtWidgets.QComboBox should do when a new string is entered by the user.

Constant Description
QComboBox.NoInsert The string will not be inserted into the combobox.
QComboBox.InsertAtTop The string will be inserted as the first item in the combobox.
QComboBox.InsertAtCurrent The current item will be replaced by the string.
QComboBox.InsertAtBottom The string will be inserted after the last item in the combobox.
QComboBox.InsertAfterCurrent The string is inserted after the current item in the combobox.
QComboBox.InsertBeforeCurrent The string is inserted before the current item in the combobox.
QComboBox.InsertAlphabetically The string is inserted in the alphabetic order in the combobox.
PySide2.QtWidgets.QComboBox.SizeAdjustPolicy

This enum specifies how the size hint of the PySide2.QtWidgets.QComboBox should adjust when new content is added or content changes.

Constant Description
QComboBox.AdjustToContents The combobox will always adjust to the contents
QComboBox.AdjustToContentsOnFirstShow The combobox will adjust to its contents the first time it is shown.
QComboBox.AdjustToMinimumContentsLength Use or instead.
QComboBox.AdjustToMinimumContentsLengthWithIcon The combobox will adjust to PySide2.QtWidgets.QComboBox.minimumContentsLength() plus space for an icon. For performance reasons use this policy on large models.
PySide2.QtWidgets.QComboBox.activated(arg__1)
Parameters:arg__1 – unicode
PySide2.QtWidgets.QComboBox.activated(index)
Parameters:indexPySide2.QtCore.int
PySide2.QtWidgets.QComboBox.addItem(text[, userData=None])
Parameters:
  • text – unicode
  • userData – object

Adds an item to the combobox with the given text , and containing the specified userData (stored in the Qt.UserRole ). The item is appended to the list of existing items.

PySide2.QtWidgets.QComboBox.addItem(icon, text[, userData=None])
Parameters:

Adds an item to the combobox with the given icon and text , and containing the specified userData (stored in the Qt.UserRole ). The item is appended to the list of existing items.

PySide2.QtWidgets.QComboBox.addItems(texts)
Parameters:texts – list of strings

Adds each of the strings in the given texts to the combobox. Each item is appended to the list of existing items in turn.

PySide2.QtWidgets.QComboBox.autoCompletion()
Return type:PySide2.QtCore.bool

Use PySide2.QtWidgets.QComboBox.setCompleter() instead.

PySide2.QtWidgets.QComboBox.autoCompletionCaseSensitivity()
Return type:PySide2.QtCore.Qt.CaseSensitivity

Use PySide2.QtWidgets.QComboBox.setCompleter() and QCompleter.setCaseSensitivity() instead.

PySide2.QtWidgets.QComboBox.clear()

Clears the combobox, removing all items.

Note: If you have set an external model on the combobox this model will still be cleared when calling this function.

PySide2.QtWidgets.QComboBox.clearEditText()

Clears the contents of the line edit used for editing in the combobox.

PySide2.QtWidgets.QComboBox.completer()
Return type:PySide2.QtWidgets.QCompleter

Returns the completer that is used to auto complete text input for the combobox.

PySide2.QtWidgets.QComboBox.count()
Return type:PySide2.QtCore.int
PySide2.QtWidgets.QComboBox.currentData([role=Qt.UserRole])
Parameters:rolePySide2.QtCore.int
Return type:object
PySide2.QtWidgets.QComboBox.currentIndex()
Return type:PySide2.QtCore.int
PySide2.QtWidgets.QComboBox.currentIndexChanged(index)
Parameters:indexPySide2.QtCore.int
PySide2.QtWidgets.QComboBox.currentIndexChanged(arg__1)
Parameters:arg__1 – unicode
PySide2.QtWidgets.QComboBox.currentText()
Return type:unicode
PySide2.QtWidgets.QComboBox.currentTextChanged(arg__1)
Parameters:arg__1 – unicode
PySide2.QtWidgets.QComboBox.duplicatesEnabled()
Return type:PySide2.QtCore.bool
PySide2.QtWidgets.QComboBox.editTextChanged(arg__1)
Parameters:arg__1 – unicode
PySide2.QtWidgets.QComboBox.findData(data[, role=Qt.UserRole[, flags=static_cast<Qt.MatchFlags>(Qt.MatchExactly|Qt.MatchCaseSensitive)]])
Parameters:
  • data – object
  • rolePySide2.QtCore.int
  • flagsPySide2.QtCore.Qt.MatchFlags
Return type:

PySide2.QtCore.int

Returns the index of the item containing the given data for the given role ; otherwise returns -1.

The flags specify how the items in the combobox are searched.

PySide2.QtWidgets.QComboBox.findText(text[, flags=static_cast<Qt.MatchFlags>(Qt.MatchExactly|Qt.MatchCaseSensitive)])
Parameters:
  • text – unicode
  • flagsPySide2.QtCore.Qt.MatchFlags
Return type:

PySide2.QtCore.int

Returns the index of the item containing the given text ; otherwise returns -1.

The flags specify how the items in the combobox are searched.

PySide2.QtWidgets.QComboBox.hasFrame()
Return type:PySide2.QtCore.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 PySide2.QtWidgets.QComboBox.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)
Parameters:arg__1 – unicode
PySide2.QtWidgets.QComboBox.highlighted(index)
Parameters:indexPySide2.QtCore.int
PySide2.QtWidgets.QComboBox.iconSize()
Return type:PySide2.QtCore.QSize
PySide2.QtWidgets.QComboBox.initStyleOption(option)
Parameters:optionPySide2.QtWidgets.QStyleOptionComboBox

Initialize option with the values from this PySide2.QtWidgets.QComboBox . This method is useful for subclasses when they need a PySide2.QtWidgets.QStyleOptionComboBox , but don’t want to fill in all the information themselves.

PySide2.QtWidgets.QComboBox.inputMethodQuery(query, argument)
Parameters:
  • queryPySide2.QtCore.Qt.InputMethodQuery
  • argument – object
Return type:

object

PySide2.QtWidgets.QComboBox.insertItem(index, text[, userData=None])
Parameters:
  • indexPySide2.QtCore.int
  • text – unicode
  • userData – object

Inserts the text and userData (stored in the Qt.UserRole ) into the combobox at the given 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, icon, text[, userData=None])
Parameters:
  • indexPySide2.QtCore.int
  • iconPySide2.QtGui.QIcon
  • text – unicode
  • userData – object

Inserts the icon , text and userData (stored in the Qt.UserRole ) into the combobox at the given 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)
Parameters:
  • indexPySide2.QtCore.int
  • texts – list of strings

Inserts the strings from the list into the combobox as separate items, starting at the index specified.

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()
Return type:PySide2.QtWidgets.QComboBox.InsertPolicy
PySide2.QtWidgets.QComboBox.insertSeparator(index)
Parameters:indexPySide2.QtCore.int

Inserts a separator item into the combobox at the given 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()
Return type:PySide2.QtCore.bool
PySide2.QtWidgets.QComboBox.itemData(index[, role=Qt.UserRole])
Parameters:
  • indexPySide2.QtCore.int
  • rolePySide2.QtCore.int
Return type:

object

Returns the data for the given role in the given index in the combobox, or QVariant.Invalid if there is no data for this role.

PySide2.QtWidgets.QComboBox.itemDelegate()
Return type:PySide2.QtWidgets.QAbstractItemDelegate

Returns the item delegate used by the popup list view.

PySide2.QtWidgets.QComboBox.itemIcon(index)
Parameters:indexPySide2.QtCore.int
Return type:PySide2.QtGui.QIcon

Returns the icon for the given index in the combobox.

PySide2.QtWidgets.QComboBox.itemText(index)
Parameters:indexPySide2.QtCore.int
Return type:unicode

Returns the text for the given index in the combobox.

PySide2.QtWidgets.QComboBox.lineEdit()
Return type:PySide2.QtWidgets.QLineEdit

Returns the line edit used to edit items in the combobox, or 0 if there is no line edit.

Only editable combo boxes have a line edit.

PySide2.QtWidgets.QComboBox.maxCount()
Return type:PySide2.QtCore.int
PySide2.QtWidgets.QComboBox.maxVisibleItems()
Return type:PySide2.QtCore.int
PySide2.QtWidgets.QComboBox.minimumContentsLength()
Return type:PySide2.QtCore.int
PySide2.QtWidgets.QComboBox.model()
Return type:PySide2.QtCore.QAbstractItemModel

Returns the model used by the combobox.

PySide2.QtWidgets.QComboBox.modelColumn()
Return type:PySide2.QtCore.int
PySide2.QtWidgets.QComboBox.removeItem(index)
Parameters:indexPySide2.QtCore.int

Removes the item at the given index from the combobox. This will update the current index if the index is removed.

This function does nothing if index is out of range.

PySide2.QtWidgets.QComboBox.rootModelIndex()
Return type:PySide2.QtCore.QModelIndex

Returns the root model item index for the items in the combobox.

PySide2.QtWidgets.QComboBox.setAutoCompletion(enable)
Parameters:enablePySide2.QtCore.bool

Use PySide2.QtWidgets.QComboBox.setCompleter() instead.

PySide2.QtWidgets.QComboBox.setAutoCompletionCaseSensitivity(sensitivity)
Parameters:sensitivityPySide2.QtCore.Qt.CaseSensitivity

Use PySide2.QtWidgets.QComboBox.setCompleter() and QCompleter.setCaseSensitivity() instead.

PySide2.QtWidgets.QComboBox.setCompleter(c)
Parameters:cPySide2.QtWidgets.QCompleter

Sets the completer to use instead of the current completer. If completer is 0, auto completion is disabled.

By default, for an editable combo box, a PySide2.QtWidgets.QCompleter that performs case insensitive inline completion is automatically created.

Note

The completer is removed when the editable() property becomes false .

PySide2.QtWidgets.QComboBox.setCurrentIndex(index)
Parameters:indexPySide2.QtCore.int
PySide2.QtWidgets.QComboBox.setCurrentText(text)
Parameters:text – unicode
PySide2.QtWidgets.QComboBox.setDuplicatesEnabled(enable)
Parameters:enablePySide2.QtCore.bool
PySide2.QtWidgets.QComboBox.setEditText(text)
Parameters:text – unicode

Sets the text in the combobox’s text edit.

PySide2.QtWidgets.QComboBox.setEditable(editable)
Parameters:editablePySide2.QtCore.bool
PySide2.QtWidgets.QComboBox.setFrame(arg__1)
Parameters:arg__1PySide2.QtCore.bool
PySide2.QtWidgets.QComboBox.setIconSize(size)
Parameters:sizePySide2.QtCore.QSize
PySide2.QtWidgets.QComboBox.setInsertPolicy(policy)
Parameters:policyPySide2.QtWidgets.QComboBox.InsertPolicy
PySide2.QtWidgets.QComboBox.setItemData(index, value[, role=Qt.UserRole])
Parameters:
  • indexPySide2.QtCore.int
  • value – object
  • rolePySide2.QtCore.int

Sets the data role for the item on the given index in the combobox to the specified value .

PySide2.QtWidgets.QComboBox.setItemDelegate(delegate)
Parameters:delegatePySide2.QtWidgets.QAbstractItemDelegate

Sets the item delegate for the popup list view. The combobox takes ownership of the delegate.

Warning

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 PySide2.QtWidgets.QAbstractItemDelegate.closeEditor() signal, and attempt to access, modify or close an editor that has already been closed.

PySide2.QtWidgets.QComboBox.setItemIcon(index, icon)
Parameters:

Sets the icon for the item on the given index in the combobox.

PySide2.QtWidgets.QComboBox.setItemText(index, text)
Parameters:
  • indexPySide2.QtCore.int
  • text – unicode

Sets the text for the item on the given index in the combobox.

PySide2.QtWidgets.QComboBox.setLineEdit(edit)
Parameters:editPySide2.QtWidgets.QLineEdit

Sets the line edit to use instead of the current line edit widget.

The combo box takes ownership of the line edit.

PySide2.QtWidgets.QComboBox.setMaxCount(max)
Parameters:maxPySide2.QtCore.int
PySide2.QtWidgets.QComboBox.setMaxVisibleItems(maxItems)
Parameters:maxItemsPySide2.QtCore.int
PySide2.QtWidgets.QComboBox.setMinimumContentsLength(characters)
Parameters:charactersPySide2.QtCore.int
PySide2.QtWidgets.QComboBox.setModel(model)
Parameters:modelPySide2.QtCore.QAbstractItemModel

Sets the model to be model . model must not be 0. If you want to clear the contents of a model, call PySide2.QtWidgets.QComboBox.clear() .

PySide2.QtWidgets.QComboBox.setModelColumn(visibleColumn)
Parameters:visibleColumnPySide2.QtCore.int
PySide2.QtWidgets.QComboBox.setRootModelIndex(index)
Parameters:indexPySide2.QtCore.QModelIndex

Sets the root model item index for the items in the combobox.

PySide2.QtWidgets.QComboBox.setSizeAdjustPolicy(policy)
Parameters:policyPySide2.QtWidgets.QComboBox.SizeAdjustPolicy
PySide2.QtWidgets.QComboBox.setValidator(v)
Parameters:vPySide2.QtGui.QValidator

Sets the validator to use instead of the current validator.

Note

The validator is removed when the editable() property becomes false .

PySide2.QtWidgets.QComboBox.setView(itemView)
Parameters:itemViewPySide2.QtWidgets.QAbstractItemView

Sets the view to be used in the combobox popup to the given itemView . The combobox takes ownership of the view.

Note: If you want to use the convenience views (like PySide2.QtWidgets.QListWidget , PySide2.QtWidgets.QTableWidget or PySide2.QtWidgets.QTreeWidget ), make sure to call PySide2.QtWidgets.QComboBox.setModel() on the combobox with the convenience widgets model before calling this function.

PySide2.QtWidgets.QComboBox.showPopup()

Displays the list of items in the combobox. If the list is empty then the no items will be shown.

If you reimplement this function to show a custom pop-up, make sure you call PySide2.QtWidgets.QComboBox.hidePopup() to reset the internal state.

PySide2.QtWidgets.QComboBox.sizeAdjustPolicy()
Return type:PySide2.QtWidgets.QComboBox.SizeAdjustPolicy
PySide2.QtWidgets.QComboBox.validator()
Return type:PySide2.QtGui.QValidator

Returns the validator that is used to constrain text input for the combobox.

PySide2.QtWidgets.QComboBox.view()
Return type:PySide2.QtWidgets.QAbstractItemView

Returns the list view used for the combobox popup.