QComboBox#

The QComboBox widget combines a button with a dropdown list. More

Inheritance diagram of PySide6.QtWidgets.QComboBox

Inherited by: QFontComboBox

Synopsis#

Properties#

  • count - The number of items in the combobox

  • currentData - The data for the current item

  • currentIndex - The index of the current item in the combobox

  • currentText - The current text

  • duplicatesEnabled - Whether the user can enter duplicate items into the combobox

  • editable - Whether the combo box can be edited by the user

  • frame - Whether the combo box draws itself with a frame

  • iconSize - The size of the icons shown in the combobox

  • insertPolicy - The policy used to determine where user-inserted items should appear in the combobox

  • maxCount - The maximum number of items allowed in the combobox

  • maxVisibleItems - The maximum allowed size on screen of the combo box, measured in items

  • minimumContentsLength - The minimum number of characters that should fit into the combobox

  • modelColumn - The column in the model that is visible

  • placeholderText - Sets a placeholderText text shown when no valid index is set

  • sizeAdjustPolicy - The policy describing how the size of the combobox changes when the content changes

Functions#

Virtual functions#

Slots#

Signals#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

collapsed_combobox1

Collapsed QCombobox

expanded_combobox2

Expanded QCombobox

Display Features#

A QComboBox is a compact way to present a list of options to the user.

A combobox is a selection widget that shows the current item, and pops up a list of selectable items when clicked. Comboboxes can contain pixmaps as well as strings if the insertItem() and setItemText() functions are suitably overloaded.

Editing Features#

A combobox may be editable, allowing the user to modify each item in the list. For editable comboboxes, the function clearEditText() is provided, to clear the displayed string without changing the combobox’s contents.

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 setInsertPolicy() .

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

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

Signals#

There are three signals emitted if the current item of a combobox changes: currentIndexChanged() , currentTextChanged() , and activated() . currentIndexChanged() and currentTextChanged() are always emitted regardless if the change was done programmatically or by user interaction, while activated() is only emitted when the change is caused by user interaction. The 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 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 editTextChanged() signal is emitted.

Model/View Framework#

QComboBox uses the model/view framework for its popup list and to store its items. By default a QStandardItemModel stores the items and a QListView subclass displays the popuplist. You can access the model and view directly (with model() and view() ), but QComboBox also provides functions to set and get item data, for example, setItemData() and itemText() . You can also set a new model and view (with setModel() and 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

You cannot alter the SelectionMode of the view() , for example, by using setSelectionMode() .

class PySide6.QtWidgets.QComboBox([parent=None])#
Parameters:

parentPySide6.QtWidgets.QWidget

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

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property PᅟySide6.QtWidgets.QComboBox.count: int#

This property holds the number of items in the combobox..

By default, for an empty combo box, this property has a value of 0.

Access functions:
property PᅟySide6.QtWidgets.QComboBox.currentData: object#

This property holds the data for the current item.

By default, for an empty combo box or a combo box in which no current item is set, this property contains an invalid QVariant.

Access functions:
property PᅟySide6.QtWidgets.QComboBox.currentIndex: int#

This property holds the index of the current item in the combobox..

The current index can change when inserting or removing items.

By default, for an empty combo box or a combo box in which no current item is set, this property has a value of -1.

Access functions:
property PᅟySide6.QtWidgets.QComboBox.currentText: str#

This property holds the current text.

If the combo box is editable, the current text is the value displayed by the line edit. Otherwise, it is the value of the current item or an empty string if the combo box is empty or no current item is set.

The setter setCurrentText() simply calls setEditText() if the combo box is editable. Otherwise, if there is a matching text in the list, currentIndex is set to the corresponding index.

See also

editable setEditText()

Access functions:
property PᅟySide6.QtWidgets.QComboBox.duplicatesEnabled: bool#

This property holds whether the user can enter duplicate items into the combobox..

Note that it is always possible to programmatically insert duplicate items into the combobox.

By default, this property is false (duplicates are not allowed).

Access functions:
property PᅟySide6.QtWidgets.QComboBox.editable: bool#

This property holds whether the combo box can be edited by the user..

By default, this property is false. The effect of editing depends on the insert policy.

Note

When disabling the editable state, the validator and completer are removed.

See also

InsertPolicy

Access functions:
property PᅟySide6.QtWidgets.QComboBox.frame: bool#

This property holds whether the combo box draws itself with a frame..

If enabled (the default) the combo box draws itself inside a frame, otherwise the combo box draws itself without any frame.

Access functions:
property PᅟySide6.QtWidgets.QComboBox.iconSize: PySide6.QtCore.QSize#

This property holds the size of the icons shown in the combobox..

Unless explicitly set this returns the default value of the current style. This size is the maximum size that icons can have; icons of smaller size are not scaled up.

Access functions:
property PᅟySide6.QtWidgets.QComboBox.insertPolicy: InsertPolicy#

This property holds the policy used to determine where user-inserted items should appear in the combobox..

The default value is InsertAtBottom , indicating that new items will appear at the bottom of the list of items.

See also

InsertPolicy

Access functions:
property PᅟySide6.QtWidgets.QComboBox.maxCount: int#

This property holds the maximum number of items allowed in the combobox..

Note

If you set the maximum number to be less then the current amount of items in the combobox, the extra items will be truncated. This also applies if you have set an external model on the combobox.

By default, this property’s value is derived from the highest signed integer available (typically 2147483647).

Access functions:
property PᅟySide6.QtWidgets.QComboBox.maxVisibleItems: int#

This property holds the maximum allowed size on screen of the combo box, measured in items.

By default, this property has a value of 10.

Note

This property is ignored for non-editable comboboxes in styles that returns true for SH_ComboBox_Popup such as the Mac style or the Gtk+ Style.

Access functions:
property PᅟySide6.QtWidgets.QComboBox.minimumContentsLength: int#

This property holds the minimum number of characters that should fit into the combobox..

The default value is 0.

If this property is set to a positive value, the minimumSizeHint() and sizeHint() take it into account.

See also

sizeAdjustPolicy

Access functions:
property PᅟySide6.QtWidgets.QComboBox.modelColumn: int#

This property holds the column in the model that is visible..

If set prior to populating the combo box, the pop-up view will not be affected and will show the first column (using this property’s default value).

By default, this property has a value of 0.

Note

In an editable combobox, the visible column will also become the completion column .

Access functions:
property PᅟySide6.QtWidgets.QComboBox.placeholderText: str#

This property holds Sets a placeholderText text shown when no valid index is set..

The placeholderText will be shown when an invalid index is set. The text is not accessible in the dropdown list. When this function is called before items are added the placeholder text will be shown, otherwise you have to call setCurrentIndex (-1) programmatically if you want to show the placeholder text. Set an empty placeholder text to reset the setting.

When the QComboBox is editable, use setPlaceholderText() instead.

Access functions:
property PᅟySide6.QtWidgets.QComboBox.sizeAdjustPolicy: SizeAdjustPolicy#

This property holds the policy describing how the size of the combobox changes when the content changes..

The default value is AdjustToContentsOnFirstShow .

See also

SizeAdjustPolicy

Access functions:
PySide6.QtWidgets.QComboBox.InsertPolicy#

This enum specifies what the 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.

PySide6.QtWidgets.QComboBox.SizeAdjustPolicy#

This enum specifies how the size hint of the 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.AdjustToMinimumContentsLengthWithIcon

The combobox will adjust to minimumContentsLength plus space for an icon. For performance reasons use this policy on large models.

PySide6.QtWidgets.QComboBox.activated(index)#
Parameters:

index – int

This signal is sent when the user chooses an item in the combobox. The item’s index is passed. Note that this signal is sent even when the choice is not changed. If you need to know when the choice actually changes, use signal currentIndexChanged() or currentTextChanged() .

PySide6.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.

PySide6.QtWidgets.QComboBox.addItem(text[, userData=None])
Parameters:
  • text – str

  • 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.

PySide6.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.

PySide6.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.

PySide6.QtWidgets.QComboBox.clearEditText()#

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

PySide6.QtWidgets.QComboBox.completer()#
Return type:

PySide6.QtWidgets.QCompleter

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

See also

setCompleter() editable

PySide6.QtWidgets.QComboBox.count()#
Return type:

int

Getter of property count .

PySide6.QtWidgets.QComboBox.currentData([role=Qt.UserRole])#
Parameters:

role – int

Return type:

object

PySide6.QtWidgets.QComboBox.currentIndex()#
Return type:

int

Getter of property currentIndex .

PySide6.QtWidgets.QComboBox.currentIndexChanged(index)#
Parameters:

index – int

This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. The item’s index is passed or -1 if the combobox becomes empty or the currentIndex was reset.

Notification signal of property currentIndex .

PySide6.QtWidgets.QComboBox.currentText()#
Return type:

str

See also

setCurrentText()

Getter of property currentText .

PySide6.QtWidgets.QComboBox.currentTextChanged(arg__1)#
Parameters:

arg__1 – str

This signal is emitted whenever currentText changes. The new value is passed as text.

Note

It is not emitted, if currentText remains the same, even if currentIndex changes.

Notification signal of property currentText .

PySide6.QtWidgets.QComboBox.duplicatesEnabled()#
Return type:

bool

Getter of property duplicatesEnabled .

PySide6.QtWidgets.QComboBox.editTextChanged(arg__1)#
Parameters:

arg__1 – str

This signal is emitted when the text in the combobox’s line edit widget is changed. The new text is specified by text.

PySide6.QtWidgets.QComboBox.findData(data[, role=Qt.UserRole[, flags=static_cast<Qt.MatchFlags>(Qt.MatchExactly|Qt.MatchCaseSensitive)]])#
Parameters:
  • data – object

  • role – int

  • flags – Combination of Qt.MatchFlag

Return type:

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.

PySide6.QtWidgets.QComboBox.findText(text[, flags=static_cast<Qt.MatchFlags>(Qt.MatchExactly|Qt.MatchCaseSensitive)])#
Parameters:
Return type:

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.

PySide6.QtWidgets.QComboBox.hasFrame()#
Return type:

bool

Getter of property frame .

PySide6.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 hidePopup() 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.

See also

showPopup()

PySide6.QtWidgets.QComboBox.highlighted(index)#
Parameters:

index – int

This signal is sent when an item in the combobox popup list is highlighted by the user. The item’s index is passed.

PySide6.QtWidgets.QComboBox.iconSize()#
Return type:

PySide6.QtCore.QSize

See also

setIconSize()

Getter of property iconSize .

PySide6.QtWidgets.QComboBox.initStyleOption(option)#
Parameters:

optionPySide6.QtWidgets.QStyleOptionComboBox

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

See also

initFrom()

PySide6.QtWidgets.QComboBox.inputMethodQuery(query, argument)#
Parameters:
Return type:

object

PySide6.QtWidgets.QComboBox.insertItem(index, icon, text[, userData=None])#
Parameters:

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.

See also

insertItems()

PySide6.QtWidgets.QComboBox.insertItem(index, text[, userData=None])
Parameters:
  • index – int

  • text – str

  • 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.

See also

insertItems()

PySide6.QtWidgets.QComboBox.insertItems(index, texts)#
Parameters:
  • index – 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.

See also

insertItem()

PySide6.QtWidgets.QComboBox.insertPolicy()#
Return type:

InsertPolicy

Getter of property insertPolicy .

PySide6.QtWidgets.QComboBox.insertSeparator(index)#
Parameters:

index – 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.

See also

insertItem()

PySide6.QtWidgets.QComboBox.isEditable()#
Return type:

bool

Getter of property editable .

PySide6.QtWidgets.QComboBox.itemData(index[, role=Qt.UserRole])#
Parameters:
  • index – int

  • role – int

Return type:

object

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

See also

setItemData()

PySide6.QtWidgets.QComboBox.itemDelegate()#
Return type:

PySide6.QtWidgets.QAbstractItemDelegate

Returns the item delegate used by the popup list view.

PySide6.QtWidgets.QComboBox.itemIcon(index)#
Parameters:

index – int

Return type:

PySide6.QtGui.QIcon

Returns the icon for the given index in the combobox.

See also

setItemIcon()

PySide6.QtWidgets.QComboBox.itemText(index)#
Parameters:

index – int

Return type:

str

Returns the text for the given index in the combobox.

See also

setItemText()

PySide6.QtWidgets.QComboBox.lineEdit()#
Return type:

PySide6.QtWidgets.QLineEdit

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

Only editable combo boxes have a line edit.

See also

setLineEdit()

PySide6.QtWidgets.QComboBox.maxCount()#
Return type:

int

See also

setMaxCount()

Getter of property maxCount .

PySide6.QtWidgets.QComboBox.maxVisibleItems()#
Return type:

int

Getter of property maxVisibleItems .

PySide6.QtWidgets.QComboBox.minimumContentsLength()#
Return type:

int

Getter of property minimumContentsLength .

PySide6.QtWidgets.QComboBox.model()#
Return type:

PySide6.QtCore.QAbstractItemModel

Returns the model used by the combobox.

See also

setModel()

PySide6.QtWidgets.QComboBox.modelColumn()#
Return type:

int

See also

setModelColumn()

Getter of property modelColumn .

PySide6.QtWidgets.QComboBox.placeholderText()#
Return type:

str

Getter of property placeholderText .

PySide6.QtWidgets.QComboBox.removeItem(index)#
Parameters:

index – 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.

PySide6.QtWidgets.QComboBox.rootModelIndex()#
Return type:

PySide6.QtCore.QModelIndex

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

PySide6.QtWidgets.QComboBox.setCompleter(c)#
Parameters:

cPySide6.QtWidgets.QCompleter

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

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

Note

The completer is removed when the editable property becomes false, or when the line edit is replaced by a call to setLineEdit() . Setting a completer on a QComboBox that is not editable will be ignored.

See also

completer()

PySide6.QtWidgets.QComboBox.setCurrentIndex(index)#
Parameters:

index – int

See also

currentIndex()

Setter of property currentIndex .

PySide6.QtWidgets.QComboBox.setCurrentText(text)#
Parameters:

text – str

See also

currentText()

Setter of property currentText .

PySide6.QtWidgets.QComboBox.setDuplicatesEnabled(enable)#
Parameters:

enable – bool

Setter of property duplicatesEnabled .

PySide6.QtWidgets.QComboBox.setEditText(text)#
Parameters:

text – str

Sets the text in the combobox’s text edit.

PySide6.QtWidgets.QComboBox.setEditable(editable)#
Parameters:

editable – bool

See also

isEditable()

Setter of property editable .

PySide6.QtWidgets.QComboBox.setFrame(arg__1)#
Parameters:

arg__1 – bool

See also

hasFrame()

Setter of property frame .

PySide6.QtWidgets.QComboBox.setIconSize(size)#
Parameters:

sizePySide6.QtCore.QSize

See also

iconSize()

Setter of property iconSize .

PySide6.QtWidgets.QComboBox.setInsertPolicy(policy)#
Parameters:

policyInsertPolicy

See also

insertPolicy()

Setter of property insertPolicy .

PySide6.QtWidgets.QComboBox.setItemData(index, value[, role=Qt.UserRole])#
Parameters:
  • index – int

  • value – object

  • role – int

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

See also

itemData()

PySide6.QtWidgets.QComboBox.setItemDelegate(delegate)#
Parameters:

delegatePySide6.QtWidgets.QAbstractItemDelegate

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

Any existing delegate will be removed, but not deleted. QComboBox does not take ownership of 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 closeEditor() signal, and attempt to access, modify or close an editor that has already been closed.

See also

itemDelegate()

PySide6.QtWidgets.QComboBox.setItemIcon(index, icon)#
Parameters:

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

See also

itemIcon()

PySide6.QtWidgets.QComboBox.setItemText(index, text)#
Parameters:
  • index – int

  • text – str

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

See also

itemText()

PySide6.QtWidgets.QComboBox.setLineEdit(edit)#
Parameters:

editPySide6.QtWidgets.QLineEdit

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

The combo box takes ownership of the line edit.

Note

Since the combobox’s line edit owns the QCompleter , any previous call to setCompleter() will no longer have any effect.

See also

lineEdit()

PySide6.QtWidgets.QComboBox.setMaxCount(max)#
Parameters:

max – int

See also

maxCount()

Setter of property maxCount .

PySide6.QtWidgets.QComboBox.setMaxVisibleItems(maxItems)#
Parameters:

maxItems – int

Setter of property maxVisibleItems .

PySide6.QtWidgets.QComboBox.setMinimumContentsLength(characters)#
Parameters:

characters – int

Setter of property minimumContentsLength .

PySide6.QtWidgets.QComboBox.setModel(model)#
Parameters:

modelPySide6.QtCore.QAbstractItemModel

Sets the model to be model. model must not be None. If you want to clear the contents of a model, call clear() .

Note

If the combobox is editable, then the model will also be set on the completer of the line edit.

PySide6.QtWidgets.QComboBox.setModelColumn(visibleColumn)#
Parameters:

visibleColumn – int

See also

modelColumn()

Setter of property modelColumn .

PySide6.QtWidgets.QComboBox.setPlaceholderText(placeholderText)#
Parameters:

placeholderText – str

Setter of property placeholderText .

PySide6.QtWidgets.QComboBox.setRootModelIndex(index)#
Parameters:

indexPySide6.QtCore.QModelIndex

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

See also

rootModelIndex()

PySide6.QtWidgets.QComboBox.setSizeAdjustPolicy(policy)#
Parameters:

policySizeAdjustPolicy

Setter of property sizeAdjustPolicy .

PySide6.QtWidgets.QComboBox.setValidator(v)#
Parameters:

vPySide6.QtGui.QValidator

Sets the validator to use instead of the current validator.

Note

The validator is removed when the editable property becomes false.

See also

validator()

PySide6.QtWidgets.QComboBox.setView(itemView)#
Parameters:

itemViewPySide6.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 QListWidget , QTableWidget or QTreeWidget ), make sure to call setModel() on the combobox with the convenience widgets model before calling this function.

See also

view()

PySide6.QtWidgets.QComboBox.showPopup()#

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

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

See also

hidePopup()

PySide6.QtWidgets.QComboBox.sizeAdjustPolicy()#
Return type:

SizeAdjustPolicy

Getter of property sizeAdjustPolicy .

PySide6.QtWidgets.QComboBox.textActivated(arg__1)#
Parameters:

arg__1 – str

This signal is sent when the user chooses an item in the combobox. The item’s text is passed. Note that this signal is sent even when the choice is not changed. If you need to know when the choice actually changes, use signal currentIndexChanged() or currentTextChanged() .

PySide6.QtWidgets.QComboBox.textHighlighted(arg__1)#
Parameters:

arg__1 – str

This signal is sent when an item in the combobox popup list is highlighted by the user. The item’s text is passed.

PySide6.QtWidgets.QComboBox.validator()#
Return type:

PySide6.QtGui.QValidator

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

See also

setValidator() editable

PySide6.QtWidgets.QComboBox.view()#
Return type:

PySide6.QtWidgets.QAbstractItemView

Returns the list view used for the combobox popup.

See also

setView()