QComboBox Class Reference

[QtGui module]

该QComboBox表示widget是一个组合键,弹出的列表中。More…

继承QWidget

通过继承QFontComboBox

Types

  • enum InsertPolicy { NoInsert, InsertAtTop, InsertAtCurrent, InsertAtBottom, ..., InsertAlphabetically }
  • enum SizeAdjustPolicy { AdjustToContents, AdjustToContentsOnFirstShow, AdjustToMinimumContentsLength, AdjustToMinimumContentsLengthWithIcon }

Methods

  • __init__ (self, QWidget parent = None)
  • addItem (self, QString text, QVariant userData = QVariant())
  • addItem (self, QIcon icon, QString text, QVariant userData = QVariant())
  • addItems (self, QStringList texts)
  • bool autoCompletion (self)
  • Qt.CaseSensitivity autoCompletionCaseSensitivity (self)
  • changeEvent (self, QEvent e)
  • clear (self)
  • clearEditText (self)
  • QCompleter completer (self)
  • contextMenuEvent (self, QContextMenuEvent e)
  • int count (self)
  • int currentIndex (self)
  • QString currentText (self)
  • bool duplicatesEnabled (self)
  • bool event (self, QEvent event)
  • int findData (self, QVariant data, int role = Qt.UserRole, Qt.MatchFlags flags = Qt.MatchExactly|Qt.MatchCaseSensitive)
  • int findText (self, QString text, Qt.MatchFlags flags = Qt.MatchExactly|Qt.MatchCaseSensitive)
  • focusInEvent (self, QFocusEvent e)
  • focusOutEvent (self, QFocusEvent e)
  • bool hasFrame (self)
  • hideEvent (self, QHideEvent e)
  • hidePopup (self)
  • QSize iconSize (self)
  • initStyleOption (self, QStyleOptionComboBox option)
  • inputMethodEvent (self, QInputMethodEvent)
  • QVariant inputMethodQuery (self, Qt.InputMethodQuery)
  • insertItem (self, int index, QString text, QVariant userData = QVariant())
  • insertItem (self, int index, QIcon icon, QString text, QVariant userData = QVariant())
  • insertItems (self, int index, QStringList texts)
  • InsertPolicy insertPolicy (self)
  • insertSeparator (self, int index)
  • bool isEditable (self)
  • QVariant itemData (self, int index, int role = Qt.UserRole)
  • QAbstractItemDelegate itemDelegate (self)
  • QIcon itemIcon (self, int index)
  • QString itemText (self, int index)
  • keyPressEvent (self, QKeyEvent e)
  • keyReleaseEvent (self, QKeyEvent e)
  • QLineEdit lineEdit (self)
  • int maxCount (self)
  • int maxVisibleItems (self)
  • int minimumContentsLength (self)
  • QSize minimumSizeHint (self)
  • QAbstractItemModel model (self)
  • int modelColumn (self)
  • mousePressEvent (self, QMouseEvent e)
  • mouseReleaseEvent (self, QMouseEvent e)
  • paintEvent (self, QPaintEvent e)
  • removeItem (self, int index)
  • resizeEvent (self, QResizeEvent e)
  • QModelIndex rootModelIndex (self)
  • setAutoCompletion (self, bool enable)
  • setAutoCompletionCaseSensitivity (self, Qt.CaseSensitivity sensitivity)
  • setCompleter (self, QCompleter c)
  • setCurrentIndex (self, int index)
  • setDuplicatesEnabled (self, bool enable)
  • setEditable (self, bool editable)
  • setEditText (self, QString text)
  • setFrame (self, bool)
  • setIconSize (self, QSize size)
  • setInsertPolicy (self, InsertPolicy policy)
  • setItemData (self, int index, QVariant value, int role = Qt.UserRole)
  • setItemDelegate (self, QAbstractItemDelegate delegate)
  • setItemIcon (self, int index, QIcon icon)
  • setItemText (self, int index, QString text)
  • setLineEdit (self, QLineEdit edit)
  • setMaxCount (self, int max)
  • setMaxVisibleItems (self, int maxItems)
  • setMinimumContentsLength (self, int characters)
  • setModel (self, QAbstractItemModel model)
  • setModelColumn (self, int visibleColumn)
  • setRootModelIndex (self, QModelIndex index)
  • setSizeAdjustPolicy (self, SizeAdjustPolicy policy)
  • setValidator (self, QValidator v)
  • setView (self, QAbstractItemView itemView)
  • showEvent (self, QShowEvent e)
  • showPopup (self)
  • SizeAdjustPolicy sizeAdjustPolicy (self)
  • QSize sizeHint (self)
  • QValidator validator (self)
  • QAbstractItemView view (self)
  • wheelEvent (self, QWheelEvent e)

Special Methods

  • __len__ (self)

Qt Signals

  • void activated (int)
  • void activated (const QString&)
  • void currentIndexChanged (int)
  • void currentIndexChanged (const QString&)
  • void editTextChanged (const QString&)
  • void highlighted (int)
  • void highlighted (const QString&)

Detailed Description

该QComboBox表示widget是一个组合键,弹出的列表中。

一个QComboBox表示提供了展示的选项列表给用户的方式,佔用屏幕空间的最小量的一种手段。

组合框是一个选择窗口小部件,显示当前的项目,可以弹出的选项列表。一个ComboBox可编辑,允许用户修改列表中的每个项目。

组合框可以包含的像素图和字符串;的insertItem()和setItemText( )函数进行适当超载。对于可编辑的组合框,该功能clearEditText( )设置,可清除显示的字符串,不改变组合框的内容。

还有,如果一个组合框改变目前的项目发出的两个信号,currentIndexChanged()和activated( ) 。currentIndexChanged( )总是发出而不论这些变化以编程方式或通过用户交互来完成的,而activated()时的变化引起的用户交互只射出。该highlighted当用户高亮显示在组合框弹出列表中的一项( )信号被发射。有两个版本,一个具有存在的所有三个信号QString参数和一个与int的说法。如果用户选择或突出显示一个像素图,只有int信号被发射。每当一个可编辑的组合框的文本改变了editTextChanged()信号被发射。

当用户进入可编辑ComboBox一个新的字符串,该部件可能会或可能不会插入它,它可以在多个位置插入。默认的策略是是AtBottom但您可以使用此更改setInsertPolicy( ) 。

这是可能使用的输入限制在一个可编辑的组合框QValidatorsetValidator( ) 。默认情况下,任何输入被接受。

一个ComboBox可以使用插入功能来填充,insertItem()和insertItems( )为例。项目可以被改变setItemText( ) 。一个项目可以被移除removeItem( ) ,所有项目可以被删除clear( ) 。当前项的文本被退回currentText( ) ,和一个编号项的文本与返回text( ) 。目前的项目可以设置setCurrentIndex( ) 。在组合框的项数是由返回count();项目的最大数目可以被设置setMaxCount( ) 。您可以使用允许编辑setEditable( ) 。对于可编辑的组合框,您可以使用设置的自动完成功能setCompleter(用户)以及是否可以添加重复设置与setDuplicatesEnabled( ) 。

QComboBox表示使用model/view framework其弹出的列表中,并存储其物品。默认情况下,QStandardItemModel存储的项目和一个QListView子类显示popuplist 。您可以访问模型和视图直接(与model()和view( ) ),但QComboBox表示还提供了功能设置和获取项目数据(例如,setItemData()和itemText())。您还可以设置一个新的模型和视图(带setModel()和setView())。在组合框的标籤文本和图标,在具有该模型的数据Qt.DisplayRoleQt.DecorationRole被使用。请注意,您不能更改SelectionModeview( ),例如,通过使用setSelectionMode()

Comboboxes in the different built-in styles.


Type Documentation

  1. QComboBox.InsertPolicy

此枚举指定什么QComboBox应该做的,当一个新的字符串是由用户输入。

Constant Value Description
QComboBox.NoInsert 0 该字符串不会被插入到组合框。
QComboBox.InsertAtTop 1 该字符串将被插入在组合框中的第一项。
QComboBox.InsertAtCurrent 2 目前的项目将replaced由该字符串。
QComboBox.InsertAtBottom 3 该字符串将在ComboBox中的最后一个项目之后插入。
QComboBox.InsertAfterCurrent 4 该字符串中的组合框的当前项后插入。
QComboBox.InsertBeforeCurrent 5 该字符串中的组合框的当前项之前插入。
QComboBox.InsertAlphabetically 6 该字符串被插入在组合框中的字母顺序。
  1. QComboBox.SizeAdjustPolicy

这个枚举指定的怎么尺寸暗示QComboBox应调整当新内容被添加或内容的变化。

Constant Value Description
QComboBox.AdjustToContents 0 组合框会一直调整到内容
QComboBox.AdjustToContentsOnFirstShow 1 组合框将被调整到它的内容在第一次被示出。
QComboBox.AdjustToMinimumContentsLength 2 使用AdjustToContents或AdjustToContentsOnFirstShow代替。
QComboBox.AdjustToMinimumContentsLengthWithIcon 3 组合框将被调整到minimumContentsLength加上一个图标的空间。出于性能的考虑使用大型模型这一政策。

Method Documentation

  1. QComboBox.__init__ (self, QWidget parent = None)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个组合框与给定parent使用默认的模型QStandardItemModel

  1. QComboBox.addItem (self, QString text, QVariant userData = QVariant())

一个项添加到组合框与给定text,和包含指定userData(存储在Qt.UserRole) 。该项目被添加到现有的项目列表。

  1. QComboBox.addItem (self, QIcon icon, QString text, QVariant userData = QVariant())

一个项添加到组合框与给定icontext,和包含指定userData(存储在Qt.UserRole) 。该项目被添加到现有的项目列表。

  1. QComboBox.addItems (self, QStringList texts)

把每个串中的给定texts到ComboBox 。每个项目会附加到反过来现有项目的清单。

  1. bool QComboBox.autoCompletion (self)
  1. Qt.CaseSensitivity QComboBox.autoCompletionCaseSensitivity (self)

[

  1. QComboBox.changeEvent (self, QEvent e)

]($docs-qt.html#CaseSensitivity-enum)

从重新实现QWidget.changeEvent( ) 。

  1. QComboBox.clear (self)

这种方法也是一个Qt槽与C + +的签名void clear()

清除组合框,删除所有项目。

注意:如果您已经在组合框中设置一个外部模型调用此功能时,此模式将仍然被清除。

  1. QComboBox.clearEditText (self)

这种方法也是一个Qt槽与C + +的签名void clearEditText()

清除用于编辑的组合框的行编辑的内容。

  1. QCompleter QComboBox.completer (self)

[

返回用于自动完成文字输入的组合框的完成者。

这个函数中引入了Qt 4.2中。

]($docs-qcompleter.html)

See also setCompleter()和editable

  1. QComboBox.contextMenuEvent (self, QContextMenuEvent e)

从重新实现QWidget.contextMenuEvent( ) 。

  1. int QComboBox.count (self)
  1. int QComboBox.currentIndex (self)
  1. QString QComboBox.currentText (self)
  1. bool QComboBox.duplicatesEnabled (self)
  1. bool QComboBox.event (self, QEvent event)

从重新实现QObject.event( ) 。

  1. int QComboBox.findData (self, QVariant data, int role = Qt.UserRole, Qt.MatchFlags flags = Qt.MatchExactly|Qt.MatchCaseSensitive)

返回该项目包含给定的索引data对于给定的role否则返回-1 。

flags指定如何在ComboBox中的项目进行搜索。

  1. int QComboBox.findText (self, QString text, Qt.MatchFlags flags = Qt.MatchExactly|Qt.MatchCaseSensitive)

返回该项目包含给定的索引text否则返回-1 。

flags指定如何在ComboBox中的项目进行搜索。

  1. QComboBox.focusInEvent (self, QFocusEvent e)

从重新实现QWidget.focusInEvent( ) 。

  1. QComboBox.focusOutEvent (self, QFocusEvent e)

从重新实现QWidget.focusOutEvent( ) 。

  1. bool QComboBox.hasFrame (self)
  1. QComboBox.hideEvent (self, QHideEvent e)

从重新实现QWidget.hideEvent( ) 。

  1. QComboBox.hidePopup (self)

隐藏在组合框的项目列表,如果它是当前可见和复位内部状态,所以,如果自定义弹出被证明里面的重新实现showPopup( ) ,那么你还需要重新实现hidePopup ( )函数来隐藏你的自定义弹出并调用基类的实现来复位内部状态时,您的自定义弹出窗口部件被隐藏。

See also showPopup( ) 。

  1. QSize QComboBox.iconSize (self)

[

  1. QComboBox.initStyleOption (self, QStyleOptionComboBox option)

]($docs-qsize.html)

初始化option与其它的值QComboBox。当他们需要一个这种方法是有用的子类QStyleOptionComboBox,但不希望在所有的信息填写自己。

See also QStyleOption.initFrom( ) 。

  1. QComboBox.inputMethodEvent (self, QInputMethodEvent)

从重新实现QWidget.inputMethodEvent( ) 。

  1. QVariant QComboBox.inputMethodQuery (self, Qt.InputMethodQuery)

从重新实现QWidget.inputMethodQuery( ) 。

  1. QComboBox.insertItem (self, int index, QString text, QVariant userData = QVariant())

插入textuserData(存储在Qt.UserRole)到ComboBox在给定的index

如果该指数等于或大于总项数越高,新项目被添加到现有的项目列表。如果该指数为零或负数,则新项目追加到现有的项目清单。

See also insertItems( ) 。

  1. QComboBox.insertItem (self, int index, QIcon icon, QString text, QVariant userData = QVariant())

插入icontextuserData(存储在Qt.UserRole)到ComboBox在给定的index

如果该指数等于或大于总项数越高,新项目被添加到现有的项目列表。如果该指数为零或负数,则新项目追加到现有的项目清单。

See also insertItems( ) 。

  1. QComboBox.insertItems (self, int index, QStringList texts)

从插入字符串list到ComboBox作为单独的项目,开始于index规定。

如果该指数等于或大于总项数越高,新项目被添加到现有的项目列表。如果该指数为零或负数,则新项目追加到现有的项目清单。

See also insertItem( ) 。

  1. InsertPolicy QComboBox.insertPolicy (self)

[

  1. QComboBox.insertSeparator (self, int index)

插入分隔项目到ComboBox在给定的index

如果该指数等于或大于总项数越高,新项目被添加到现有的项目列表。如果该指数为零或负数,则新项目追加到现有的项目清单。

此功能被引入Qt的4.4 。

]($docs-qcombobox.html#InsertPolicy-enum)

See also insertItem( ) 。

  1. bool QComboBox.isEditable (self)
  1. QVariant QComboBox.itemData (self, int index, int role = Qt.UserRole)

返回数据为给定的role在给定的index在组合框,或QVariant.Invalid如果没有数据,这个作用。

See also setItemData( ) 。

  1. QAbstractItemDelegate QComboBox.itemDelegate (self)

[

返回所使用的弹出列表视图中的项目委讬。

]($docs-qabstractitemdelegate.html)

See also setItemDelegate( ) 。

  1. QIcon QComboBox.itemIcon (self, int index)

[

返回图标为给定的index在组合框。

]($docs-qicon.html)

See also setItemIcon( ) 。

  1. QString QComboBox.itemText (self, int index)

返回文本为给定的index在组合框。

See also setItemText( ) 。

  1. QComboBox.keyPressEvent (self, QKeyEvent e)

从重新实现QWidget.keyPressEvent( ) 。

  1. QComboBox.keyReleaseEvent (self, QKeyEvent e)

从重新实现QWidget.keyReleaseEvent( ) 。

  1. QLineEdit QComboBox.lineEdit (self)

[

返回用于在组合框,或0编辑项目,如果没有行编辑的行编辑。

唯一可编辑的组合框有一个行编辑。

]($docs-qlineedit.html)

See also setLineEdit( ) 。

  1. int QComboBox.maxCount (self)
  1. int QComboBox.maxVisibleItems (self)
  1. int QComboBox.minimumContentsLength (self)
  1. QSize QComboBox.minimumSizeHint (self)

从重新实现QWidget.minimumSizeHint( ) 。

  1. QAbstractItemModel QComboBox.model (self)

[

返回所使用的组合框模型。

]($docs-qabstractitemmodel.html)

See also setModel( ) 。

  1. int QComboBox.modelColumn (self)
  1. QComboBox.mousePressEvent (self, QMouseEvent e)

从重新实现QWidget.mousePressEvent( ) 。

  1. QComboBox.mouseReleaseEvent (self, QMouseEvent e)

从重新实现QWidget.mouseReleaseEvent( ) 。

  1. QComboBox.paintEvent (self, QPaintEvent e)

从重新实现QWidget.paintEvent( ) 。

  1. QComboBox.removeItem (self, int index)

删除给定的项目index从组合框。如果索引中删除这将更新当前的索引。

这个函数做什么,如果index超出范围。

  1. QComboBox.resizeEvent (self, QResizeEvent e)

从重新实现QWidget.resizeEvent( ) 。

  1. QModelIndex QComboBox.rootModelIndex (self)

[

返回根模型项目指数在ComboBox中的项目。

]($docs-qmodelindex.html)

See also setRootModelIndex( ) 。

  1. QComboBox.setAutoCompletion (self, bool enable)
  1. QComboBox.setAutoCompletionCaseSensitivity (self, Qt.CaseSensitivity sensitivity)
  1. QComboBox.setCompleter (self, QCompleter c)

设置completer使用而不是目前的完成者的。如果completer为0 ,自动完成被禁用。

默认情况下,一个可编辑的组合框,一个QCompleter执行不区分大小写的直列完成自动创建。

这个函数中引入了Qt 4.2中。

See also completer( ) 。

  1. QComboBox.setCurrentIndex (self, int index)
  1. QComboBox.setDuplicatesEnabled (self, bool enable)
  1. QComboBox.setEditable (self, bool editable)
  1. QComboBox.setEditText (self, QString text)

这种方法也是一个Qt槽与C + +的签名void setEditText(const QString&)

设置text在组合框的文本编辑。

  1. QComboBox.setFrame (self, bool)
  1. QComboBox.setIconSize (self, QSize size)
  1. QComboBox.setInsertPolicy (self, InsertPolicy policy)
  1. QComboBox.setItemData (self, int index, QVariant value, int role = Qt.UserRole)

设置数据role在给定的产品index在组合框来指定value

See also itemData( ) 。

  1. QComboBox.setItemDelegate (self, QAbstractItemDelegate delegate)

设置项delegate在弹出的列表视图。组合框采用委讬的所有权。

Warning:你不应该共享组合框,控件映射程序或视图之间的委讬的同一实例。否则会导致不正确或不直观的编辑行为,因为在一个给定的委讬每个视图可能会收到closeEditor()信号,并试图访问,修改或关闭一个已经被关闭的编辑器。

See also itemDelegate( ) 。

  1. QComboBox.setItemIcon (self, int index, QIcon icon)

设置icon在给定的产品index在组合框。

See also itemIcon( ) 。

  1. QComboBox.setItemText (self, int index, QString text)

设置text在给定的产品index在组合框。

See also itemText( ) 。

  1. QComboBox.setLineEdit (self, QLineEdit edit)

edit说法有它的所有权转移给Qt的。

设置行edit使用而不是目前的行编辑widget的。

组合框取行编辑的所有权。

See also lineEdit( ) 。

  1. QComboBox.setMaxCount (self, int max)
  1. QComboBox.setMaxVisibleItems (self, int maxItems)
  1. QComboBox.setMinimumContentsLength (self, int characters)
  1. QComboBox.setModel (self, QAbstractItemModel model)

设置模型是modelmodel不能为0 。如果你想清除一个模型的内容,请致电clear( ) 。

See also model()和clear( ) 。

  1. QComboBox.setModelColumn (self, int visibleColumn)
  1. QComboBox.setRootModelIndex (self, QModelIndex index)

设置根模型项目index在ComboBox中的项目。

See also rootModelIndex( ) 。

  1. QComboBox.setSizeAdjustPolicy (self, SizeAdjustPolicy policy)
  1. QComboBox.setValidator (self, QValidator v)

设置validator使用而不是目前的验证器。

See also validator( ) 。

  1. QComboBox.setView (self, QAbstractItemView itemView)

itemView说法有它的所有权转移给Qt的。

设置要使用的组合框弹出给定的视图itemView。组合框采用该视图的所有权。

注意:如果你想使用的便利性意见(如QListWidgetQTableWidget or QTreeWidget) ,请确保调用setModel( )在调用此函数之前的组合框与便利的小部件的模型。

See also view( ) 。

  1. QComboBox.showEvent (self, QShowEvent e)

从重新实现QWidget.showEvent( ) 。

  1. QComboBox.showPopup (self)

显示在组合框的项目列表。如果列表为空,则没有项目将会显示。

如果你重新实现这个函数来显示一个自定义弹出,请确保您致电hidePopup()复位内部状态。

See also hidePopup( ) 。

  1. SizeAdjustPolicy QComboBox.sizeAdjustPolicy (self)

  1. QSize QComboBox.sizeHint (self)

从重新实现QWidget.sizeHint( ) 。

此实现缓存大小提示,以避免在调整大小时的内容动态改变。无效缓存的值改变sizeAdjustPolicy

  1. QValidator QComboBox.validator (self)

[

返回用来限制文字输入组合框的验证。

]($docs-qvalidator.html)

See also setValidator()和editable

  1. QAbstractItemView QComboBox.view (self)

[

返回用于组合框弹出列表视图。

]($docs-qabstractitemview.html)

See also setView( ) 。

  1. QComboBox.wheelEvent (self, QWheelEvent e)

从重新实现QWidget.wheelEvent( ) 。

  1. QComboBox.__len__ (self)

Qt Signal Documentation

  1. void activated (int)

这是该信号的默认超载。

当用户选择在ComboBox中的项目,这个信号被发送。该项目的index被传递。请注意,即使在选择时不改变此信号被发送。如果你需要知道什么时候该选择实际上改变,使用信号currentIndexChanged( ) 。

  1. void activated (const QString&)

当用户选择在ComboBox中的项目,这个信号被发送。该项目的text被传递。请注意,即使在选择时不改变此信号被发送。如果你需要知道什么时候该选择实际上改变,使用信号currentIndexChanged( ) 。

  1. void currentIndexChanged (int)

这是该信号的默认超载。

这个信号被发送时的currentIndex在组合框的变化既可以通过用户交互或编程方式。该项目的index通过或-1,如果组合框为空或currentIndex被重置。

这个函数是Qt 4.1中引入。

  1. void currentIndexChanged (const QString&)

这个信号被发送时的currentIndex在组合框的变化既可以通过用户交互或编程方式。该项目的text被传递。

这个函数是Qt 4.1中引入。

  1. void editTextChanged (const QString&)

这是该信号的默认超载。

当在组合框的行编辑插件的文本更改这个信号被发射。新的文本由指定text

  1. void highlighted (int)

这是该信号的默认超载。

当在组合框弹出列表中的项目是由用户突出显示该信号被发送。该项目的index被传递。

  1. void highlighted (const QString&)

当在组合框弹出列表中的项目是由用户突出显示该信号被发送。该项目的text被传递。