QComboBox

Inheritance diagram of QComboBox

Inherited by: QFontComboBox

Synopsis

Functions

Virtual functions

Slots

Signals

Detailed Description

The PySide.QtGui.QComboBox widget is a combined button and popup list.

A PySide.QtGui.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 PySide.QtGui.QComboBox.insertItem() and PySide.QtGui.QComboBox.setItemText() functions are suitably overloaded. For editable comboboxes, the function PySide.QtGui.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, PySide.QtGui.QComboBox.currentIndexChanged() and PySide.QtGui.QComboBox.activated() . PySide.QtGui.QComboBox.currentIndexChanged() is always emitted regardless if the change was done programmatically or by user interaction, while PySide.QtGui.QComboBox.activated() is only emitted when the change is caused by user interaction. The PySide.QtGui.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 PySide.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 PySide.QtGui.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 is AtBottom but you can change this using PySide.QtGui.QComboBox.setInsertPolicy() .

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

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

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

../../_images/qstyle-comboboxes.png

See also

PySide.QtGui.QLineEdit PySide.QtGui.QSpinBox PySide.QtGui.QRadioButton PySide.QtGui.QButtonGroup GUI Design Handbook: Combo Box, Drop-Down List Box

class PySide.QtGui.QComboBox([parent=None])
Parameters:parentPySide.QtGui.QWidget

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

PySide.QtGui.QComboBox.InsertPolicy

This enum specifies what the PySide.QtGui.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.
PySide.QtGui.QComboBox.SizeAdjustPolicy

This enum specifies how the size hint of the PySide.QtGui.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 AdjustToContents or AdjustToContentsOnFirstShow instead.
QComboBox.AdjustToMinimumContentsLengthWithIcon The combobox will adjust to PySide.QtGui.QComboBox.minimumContentsLength() plus space for an icon. For performance reasons use this policy on large models.
PySide.QtGui.QComboBox.activated(index)
Parameters:indexPySide.QtCore.int
PySide.QtGui.QComboBox.activated(arg__1)
Parameters:arg__1 – unicode
PySide.QtGui.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.

PySide.QtGui.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.

PySide.QtGui.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.

PySide.QtGui.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.

PySide.QtGui.QComboBox.clearEditText()

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

PySide.QtGui.QComboBox.completer()
Return type:PySide.QtGui.QCompleter

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

PySide.QtGui.QComboBox.count()
Return type:PySide.QtCore.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.

PySide.QtGui.QComboBox.currentIndex()
Return type:PySide.QtCore.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.

PySide.QtGui.QComboBox.currentIndexChanged(arg__1)
Parameters:arg__1 – unicode
PySide.QtGui.QComboBox.currentIndexChanged(index)
Parameters:indexPySide.QtCore.int
PySide.QtGui.QComboBox.currentText()
Return type:unicode

This property holds the text of 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 empty string.

PySide.QtGui.QComboBox.duplicatesEnabled()
Return type:PySide.QtCore.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).

PySide.QtGui.QComboBox.editTextChanged(arg__1)
Parameters:arg__1 – unicode
PySide.QtGui.QComboBox.findData(data[, role=Qt.UserRole[, flags=static_cast<Qt.MatchFlags>(Qt.MatchExactly|Qt.MatchCaseSensitive)]])
Parameters:
  • data – object
  • rolePySide.QtCore.int
  • flagsPySide.QtCore.Qt.MatchFlags
Return type:

PySide.QtCore.int

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

PySide.QtCore.int

PySide.QtGui.QComboBox.hasFrame()
Return type:PySide.QtCore.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.

PySide.QtGui.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 PySide.QtGui.QComboBox.showPopup() , then you also need to reimplement the PySide.QtGui.QComboBox.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.

PySide.QtGui.QComboBox.highlighted(arg__1)
Parameters:arg__1 – unicode
PySide.QtGui.QComboBox.highlighted(index)
Parameters:indexPySide.QtCore.int
PySide.QtGui.QComboBox.iconSize()
Return type:PySide.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.

PySide.QtGui.QComboBox.initStyleOption(option)
Parameters:optionPySide.QtGui.QStyleOptionComboBox

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

PySide.QtGui.QComboBox.insertItem(index, text[, userData=None])
Parameters:
  • indexPySide.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.

PySide.QtGui.QComboBox.insertItem(index, icon, text[, userData=None])
Parameters:
  • indexPySide.QtCore.int
  • iconPySide.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.

PySide.QtGui.QComboBox.insertItems(index, texts)
Parameters:
  • indexPySide.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.

PySide.QtGui.QComboBox.insertPolicy()
Return type:PySide.QtGui.QComboBox.InsertPolicy

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

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

See also

QComboBox.InsertPolicy

PySide.QtGui.QComboBox.insertSeparator(index)
Parameters:indexPySide.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.

PySide.QtGui.QComboBox.isEditable()
Return type:PySide.QtCore.bool

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

By default, this property is false.

PySide.QtGui.QComboBox.itemData(index[, role=Qt.UserRole])
Parameters:
  • indexPySide.QtCore.int
  • rolePySide.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.

PySide.QtGui.QComboBox.itemDelegate()
Return type:PySide.QtGui.QAbstractItemDelegate

Returns the item delegate used by the popup list view.

PySide.QtGui.QComboBox.itemIcon(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtGui.QIcon

Returns the icon for the given index in the combobox.

PySide.QtGui.QComboBox.itemText(index)
Parameters:indexPySide.QtCore.int
Return type:unicode

Returns the text for the given index in the combobox.

PySide.QtGui.QComboBox.lineEdit()
Return type:PySide.QtGui.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.

PySide.QtGui.QComboBox.maxCount()
Return type:PySide.QtCore.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).

PySide.QtGui.QComboBox.maxVisibleItems()
Return type:PySide.QtCore.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 false for QStyle.SH_ComboBox_Popup such as the Mac style or the Gtk+ Style.

PySide.QtGui.QComboBox.minimumContentsLength()
Return type:PySide.QtCore.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 PySide.QtGui.QComboBox.minimumSizeHint() and PySide.QtGui.QComboBox.sizeHint() take it into account.

PySide.QtGui.QComboBox.model()
Return type:PySide.QtCore.QAbstractItemModel

Returns the model used by the combobox.

PySide.QtGui.QComboBox.modelColumn()
Return type:PySide.QtCore.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.

PySide.QtGui.QComboBox.removeItem(index)
Parameters:indexPySide.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.

PySide.QtGui.QComboBox.rootModelIndex()
Return type:PySide.QtCore.QModelIndex

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

PySide.QtGui.QComboBox.setCompleter(c)
Parameters:cPySide.QtGui.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 PySide.QtGui.QCompleter that performs case insensitive inline completion is automatically created.

PySide.QtGui.QComboBox.setCurrentIndex(index)
Parameters:indexPySide.QtCore.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.

PySide.QtGui.QComboBox.setDuplicatesEnabled(enable)
Parameters:enablePySide.QtCore.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).

PySide.QtGui.QComboBox.setEditText(text)
Parameters:text – unicode

Sets the text in the combobox’s text edit.

PySide.QtGui.QComboBox.setEditable(editable)
Parameters:editablePySide.QtCore.bool

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

By default, this property is false.

PySide.QtGui.QComboBox.setFrame(arg__1)
Parameters:arg__1PySide.QtCore.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.

PySide.QtGui.QComboBox.setIconSize(size)
Parameters:sizePySide.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.

PySide.QtGui.QComboBox.setInsertPolicy(policy)
Parameters:policyPySide.QtGui.QComboBox.InsertPolicy

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

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

See also

QComboBox.InsertPolicy

PySide.QtGui.QComboBox.setItemData(index, value[, role=Qt.UserRole])
Parameters:
  • indexPySide.QtCore.int
  • value – object
  • rolePySide.QtCore.int

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

PySide.QtGui.QComboBox.setItemDelegate(delegate)
Parameters:delegatePySide.QtGui.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 PySide.QtGui.QAbstractItemDelegate.closeEditor() signal, and attempt to access, modify or close an editor that has already been closed.

PySide.QtGui.QComboBox.setItemIcon(index, icon)
Parameters:

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

PySide.QtGui.QComboBox.setItemText(index, text)
Parameters:
  • indexPySide.QtCore.int
  • text – unicode

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

PySide.QtGui.QComboBox.setLineEdit(edit)
Parameters:editPySide.QtGui.QLineEdit

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

The combo box takes ownership of the line edit.

PySide.QtGui.QComboBox.setMaxCount(max)
Parameters:maxPySide.QtCore.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).

PySide.QtGui.QComboBox.setMaxVisibleItems(maxItems)
Parameters:maxItemsPySide.QtCore.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 false for QStyle.SH_ComboBox_Popup such as the Mac style or the Gtk+ Style.

PySide.QtGui.QComboBox.setMinimumContentsLength(characters)
Parameters:charactersPySide.QtCore.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 PySide.QtGui.QComboBox.minimumSizeHint() and PySide.QtGui.QComboBox.sizeHint() take it into account.

PySide.QtGui.QComboBox.setModel(model)
Parameters:modelPySide.QtCore.QAbstractItemModel

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

PySide.QtGui.QComboBox.setModelColumn(visibleColumn)
Parameters:visibleColumnPySide.QtCore.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.

PySide.QtGui.QComboBox.setRootModelIndex(index)
Parameters:indexPySide.QtCore.QModelIndex

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

PySide.QtGui.QComboBox.setSizeAdjustPolicy(policy)
Parameters:policyPySide.QtGui.QComboBox.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

QComboBox.SizeAdjustPolicy

PySide.QtGui.QComboBox.setValidator(v)
Parameters:vPySide.QtGui.QValidator

Sets the validator to use instead of the current validator.

PySide.QtGui.QComboBox.setView(itemView)
Parameters:itemViewPySide.QtGui.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 PySide.QtGui.QListWidget , PySide.QtGui.QTableWidget or PySide.QtGui.QTreeWidget ), make sure to call PySide.QtGui.QComboBox.setModel() on the combobox with the convenience widgets model before calling this function.

PySide.QtGui.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 PySide.QtGui.QComboBox.hidePopup() to reset the internal state.

PySide.QtGui.QComboBox.sizeAdjustPolicy()
Return type:PySide.QtGui.QComboBox.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

QComboBox.SizeAdjustPolicy

PySide.QtGui.QComboBox.validator()
Return type:PySide.QtGui.QValidator

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

PySide.QtGui.QComboBox.view()
Return type:PySide.QtGui.QAbstractItemView

Returns the list view used for the combobox popup.