QComboBox Class

QComboBox 是一个按钮和弹出列表组合的widget. 更多...

头文件: #include <QComboBox>
qmake: QT += widgets
基类: QWidget
派生类:

QFontComboBox

公有类型

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

属性

公有函数

QComboBox(QWidget *parent = Q_NULLPTR)
~QComboBox()
void addItem(const QString &text, const QVariant &userData = QVariant())
void addItem(const QIcon &icon, const QString &text, const QVariant &userData = QVariant())
void addItems(const QStringList &texts)
QCompleter *completer() const
int count() const
QVariant currentData(int role = Qt::UserRole) const
int currentIndex() const
QString currentText() const
bool duplicatesEnabled() const
int findData(const QVariant &data, int role = Qt::UserRole, Qt::MatchFlags flags = static_cast<Qt::MatchFlags> ( Qt::MatchExactly | Qt::MatchCaseSensitive )) const
int findText(const QString &text, Qt::MatchFlags flags = static_cast<Qt::MatchFlags> ( Qt::MatchExactly | Qt::MatchCaseSensitive )) const
bool hasFrame() const
virtual void hidePopup()
QSize iconSize() const
void insertItem(int index, const QString &text, const QVariant &userData = QVariant())
void insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userData = QVariant())
void insertItems(int index, const QStringList &list)
InsertPolicy insertPolicy() const
void insertSeparator(int index)
bool isEditable() const
QVariant itemData(int index, int role = Qt::UserRole) const
QAbstractItemDelegate *itemDelegate() const
QIcon itemIcon(int index) const
QString itemText(int index) const
QLineEdit *lineEdit() const
int maxCount() const
int maxVisibleItems() const
int minimumContentsLength() const
QAbstractItemModel *model() const
int modelColumn() const
void removeItem(int index)
QModelIndex rootModelIndex() const
void setCompleter(QCompleter *completer)
void setDuplicatesEnabled(bool enable)
void setEditable(bool editable)
void setFrame(bool)
void setIconSize(const QSize &size)
void setInsertPolicy(InsertPolicy policy)
void setItemData(int index, const QVariant &value, int role = Qt::UserRole)
void setItemDelegate(QAbstractItemDelegate *delegate)
void setItemIcon(int index, const QIcon &icon)
void setItemText(int index, const QString &text)
void setLineEdit(QLineEdit *edit)
void setMaxCount(int max)
void setMaxVisibleItems(int maxItems)
void setMinimumContentsLength(int characters)
void setModel(QAbstractItemModel *model)
void setModelColumn(int visibleColumn)
void setRootModelIndex(const QModelIndex &index)
void setSizeAdjustPolicy(SizeAdjustPolicy policy)
void setValidator(const QValidator *validator)
void setView(QAbstractItemView *itemView)
virtual void showPopup()
SizeAdjustPolicy sizeAdjustPolicy() const
const QValidator *validator() const
QAbstractItemView *view() const

重新实现的公有函数

virtual bool event(QEvent *event)
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
virtual QSize minimumSizeHint() const
virtual QSize sizeHint() const

公有槽函数

void clear()
void clearEditText()
void setCurrentIndex(int index)
void setCurrentText(const QString &text)
void setEditText(const QString &text)
  • 19 个公有槽函数继承自 QWidget
  • 1 个公有槽函数继承自 QObject

信号

void activated(int index)
void activated(const QString &text)
void currentIndexChanged(int index)
void currentIndexChanged(const QString &text)
void currentTextChanged(const QString &text)
void editTextChanged(const QString &text)
void highlighted(int index)
void highlighted(const QString &text)

受保护的函数

void initStyleOption(QStyleOptionComboBox *option) const

重新实现的受保护函数

virtual void changeEvent(QEvent *e)
virtual void contextMenuEvent(QContextMenuEvent *e)
virtual void focusInEvent(QFocusEvent *e)
virtual void focusOutEvent(QFocusEvent *e)
virtual void hideEvent(QHideEvent *e)
virtual void inputMethodEvent(QInputMethodEvent *e)
virtual void keyPressEvent(QKeyEvent *e)
virtual void keyReleaseEvent(QKeyEvent *e)
virtual void mousePressEvent(QMouseEvent *e)
virtual void mouseReleaseEvent(QMouseEvent *e)
virtual void paintEvent(QPaintEvent *e)
virtual void resizeEvent(QResizeEvent *e)
virtual void showEvent(QShowEvent *e)
virtual void wheelEvent(QWheelEvent *e)
  • 35 个受保护的函数继承自 QWidget
  • 9 个受保护的函数继承自 QObject
  • 1 个受保护的函数继承自 QPaintDevice

其他继承的成员

  • 1 个公有变量继承自 QObject
  • 5 个静态公有成员继承自 QWidget
  • 10 个静态公有成员继承自 QObject
  • 1 个受保护的槽函数继承自 QWidget
  • 2 个受保护的变量继承自 QObject
  • 1 protected type inherited from QPaintDevice

详细描述

QComboBox 是一个按钮和弹出列表组合的widget.

QComboBox 提供一种占用最小屏幕空间, 向用户展示选项列表的方法.

下拉列表框显示当前选中项, 且可以弹出选项列表. 下拉列表框可以编辑, 允许用户修改列表中的子项.

调用 insertItem() 和 setItemText() 函数的重载, QComboBox 可以包含字符串及图片. 对于可编辑的下拉列表框, 调用 clearEditText() 函数清除显示的字符串而不更改下拉列表框的内容.

如果下拉列表框的当前项修改, QComboBox发出信号: currentIndexChanged() , activated(). currentIndexChanged() 信号总会发出, 无论程序修改还是用户交互, 但是 activated() 信号仅在用户交互时发出. highlighted() 信号在用户高亮一个项目时发出. 这些信号都有两个重载, 一个是 QString 参数, 一个是 int 参数. 如果用户选择或高亮一个图片, 仅发送 int 信号. 每次修改可编辑的下拉列表框的文本会发送信号 editTextChanged().

当用户在可编辑的下拉列表框输入新字符串, widget可以设置是否插入新字符串. 这个插入的默认策略是 InsertAtBottom, 你可以调用 setInsertPolicy()修改插入策略.

你可以使用 QValidator 限制可编辑的下拉组合框输入; 参见 setValidator(). 默认情况下, 下拉组合框接受任何输入.

下拉组合框最常使用的插入函数是 insertItem() 和 insertItems(). 调用 setItemText()修改项. 调用 removeItem()移除项, 调用 clear()移除所有项. 调用 currentText()获取当前项的文本, 也可调用项的 text() 函数返回文本. 调用 setCurrentIndex()设置当前项. 调用 count()获取项的数量; 调用 setMaxCount()设置最大项的数量. 调用 setEditable() 设置项是否可编辑. 对于可编辑的下拉列表, 调用 setCompleter() 设置自动补全, 调用 setDuplicatesEnabled()设置项是否可重复.

QComboBox 使用 模型/视图框架 构建弹出列表框及存储子项. 默认情况下, 使用QStandardItemModel 存储所有项, 子类化 QListView 显示弹出列表. 你能使用model() 和 view() 直接访问模型和视图, 但是 QComboBox 也提供函数访问项数据 (例如., setItemData() 和 itemText()). 你也可以调用 setModel() 和 setView()设置新的模型和视图. 对于下拉列表框中的文本和图片, 模型数据使用 Qt::DisplayRoleQt::DecorationRole. 注意: 你不能修改view()的 SelectionMode, 例如., 调用 setSelectionMode().

Comboboxes in the different built-in styles.

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

成员类型

enum QComboBox::InsertPolicy

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

ConstantValueDescription
QComboBox::NoInsert0The string will not be inserted into the combobox.
QComboBox::InsertAtTop1The string will be inserted as the first item in the combobox.
QComboBox::InsertAtCurrent2The current item will be replaced by the string.
QComboBox::InsertAtBottom3The string will be inserted after the last item in the combobox.
QComboBox::InsertAfterCurrent4The string is inserted after the current item in the combobox.
QComboBox::InsertBeforeCurrent5The string is inserted before the current item in the combobox.
QComboBox::InsertAlphabetically6The string is inserted in the alphabetic order in the combobox.

enum QComboBox::SizeAdjustPolicy

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

ConstantValueDescription
QComboBox::AdjustToContents0The combobox will always adjust to the contents
QComboBox::AdjustToContentsOnFirstShow1The combobox will adjust to its contents the first time it is shown.
QComboBox::AdjustToMinimumContentsLength2Use AdjustToContents or AdjustToContentsOnFirstShow instead.
QComboBox::AdjustToMinimumContentsLengthWithIcon3The combobox will adjust to minimumContentsLength plus space for an icon. For performance reasons use this policy on large models.

属性

count : const 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.

访问函数:

int count() const

currentData : const QVariant

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.

This property was introduced in Qt 5.2.

访问函数:

QVariant currentData(int role = Qt::UserRole) const

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.

访问函数:

int currentIndex() const
void setCurrentIndex(int index)

Notifier signal:

void currentIndexChanged(int index)
void currentIndexChanged(const QString &text)

currentText : QString

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.

访问函数:

QString currentText() const
void setCurrentText(const QString &text)

Notifier signal:

void currentTextChanged(const QString &text)

参见 editable and setEditText().

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

访问函数:

bool duplicatesEnabled() const
void setDuplicatesEnabled(bool enable)

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.

访问函数:

bool isEditable() const
void setEditable(bool editable)

参见 InsertPolicy.

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.

访问函数:

bool hasFrame() const
void setFrame(bool)

iconSize : 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.

访问函数:

QSize iconSize() const
void setIconSize(const QSize &size)

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.

访问函数:

InsertPolicy insertPolicy() const
void setInsertPolicy(InsertPolicy policy)

参见 InsertPolicy.

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

访问函数:

int maxCount() const
void setMaxCount(int max)

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 QStyle::SH_ComboBox_Popup such as the Mac style or the Gtk+ Style.

访问函数:

int maxVisibleItems() const
void setMaxVisibleItems(int maxItems)

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.

访问函数:

int minimumContentsLength() const
void setMinimumContentsLength(int characters)

参见 sizeAdjustPolicy.

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.

访问函数:

int modelColumn() const
void setModelColumn(int visibleColumn)

sizeAdjustPolicy : SizeAdjustPolicy

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

The default value is AdjustToContentsOnFirstShow.

访问函数:

SizeAdjustPolicy sizeAdjustPolicy() const
void setSizeAdjustPolicy(SizeAdjustPolicy policy)

参见 SizeAdjustPolicy.

成员函数

QComboBox::QComboBox(QWidget *parent = Q_NULLPTR)

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

QComboBox::~QComboBox()

Destroys the combobox.

[signal] void QComboBox::activated(int index)

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

Note: Signal activated is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:


  connect(comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
      [=](int index){ /* ... */ });

[signal] void QComboBox::activated(const QString &text)

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

Note: Signal activated is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:


  connect(comboBox, static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::activated),
      [=](const QString &text){ /* ... */ });

void QComboBox::addItem(const QString &text, const QVariant &userData = QVariant())

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.

void QComboBox::addItem(const QIcon &icon, const QString &text, const QVariant &userData = QVariant())

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.

void QComboBox::addItems(const QStringList &texts)

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

[virtual protected] void QComboBox::changeEvent(QEvent *e)

重新实现 QWidget::changeEvent().

[slot] void 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.

[slot] void QComboBox::clearEditText()

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

QCompleter *QComboBox::completer() const

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

This function was introduced in Qt 4.2.

参见 setCompleter() and editable.

[virtual protected] void QComboBox::contextMenuEvent(QContextMenuEvent *e)

重新实现 QWidget::contextMenuEvent().

[signal] void QComboBox::currentIndexChanged(int index)

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.

Note: Signal currentIndexChanged is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:


  connect(comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
      [=](int index){ /* ... */ });

This function was introduced in Qt 4.1.

Note: Notifier signal for property currentIndex.

[signal] void QComboBox::currentIndexChanged(const QString &text)

This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. The item's text is passed.

Note: Signal currentIndexChanged is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:


  connect(comboBox, static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
      [=](const QString &text){ /* ... */ });

This function was introduced in Qt 4.1.

Note: Notifier signal for property currentIndex.

[signal] void QComboBox::currentTextChanged(const QString &text)

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

This function was introduced in Qt 5.0.

Note: Notifier signal for property currentText.

[signal] void QComboBox::editTextChanged(const QString &text)

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

[virtual] bool QComboBox::event(QEvent *event)

重新实现 QObject::event().

int QComboBox::findData(const QVariant &data, int role = Qt::UserRole, Qt::MatchFlags flags = static_cast<Qt::MatchFlags> ( Qt::MatchExactly | Qt::MatchCaseSensitive )) const

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.

int QComboBox::findText(const QString &text, Qt::MatchFlags flags = static_cast<Qt::MatchFlags> ( Qt::MatchExactly | Qt::MatchCaseSensitive )) const

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

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

[virtual protected] void QComboBox::focusInEvent(QFocusEvent *e)

重新实现 QWidget::focusInEvent().

[virtual protected] void QComboBox::focusOutEvent(QFocusEvent *e)

重新实现 QWidget::focusOutEvent().

[virtual protected] void QComboBox::hideEvent(QHideEvent *e)

重新实现 QWidget::hideEvent().

[virtual] void 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.

参见 showPopup().

[signal] void QComboBox::highlighted(int index)

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

Note: Signal highlighted is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:


  connect(comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::highlighted),
      [=](int index){ /* ... */ });

[signal] void QComboBox::highlighted(const QString &text)

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

Note: Signal highlighted is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:


  connect(comboBox, static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::highlighted),
      [=](const QString &text){ /* ... */ });

[protected] void QComboBox::initStyleOption(QStyleOptionComboBox *option) const

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.

参见 QStyleOption::initFrom().

[virtual protected] void QComboBox::inputMethodEvent(QInputMethodEvent *e)

重新实现 QWidget::inputMethodEvent().

[virtual] QVariant QComboBox::inputMethodQuery(Qt::InputMethodQuery query) const

重新实现 QWidget::inputMethodQuery().

void QComboBox::insertItem(int index, const QString &text, const QVariant &userData = QVariant())

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.

参见 insertItems().

void QComboBox::insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userData = QVariant())

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.

参见 insertItems().

void QComboBox::insertItems(int index, const QStringList &list)

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.

参见 insertItem().

void QComboBox::insertSeparator(int index)

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.

This function was introduced in Qt 4.4.

参见 insertItem().

QVariant QComboBox::itemData(int index, int role = Qt::UserRole) const

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.

参见 setItemData().

QAbstractItemDelegate *QComboBox::itemDelegate() const

Returns the item delegate used by the popup list view.

参见 setItemDelegate().

QIcon QComboBox::itemIcon(int index) const

Returns the icon for the given index in the combobox.

参见 setItemIcon().

QString QComboBox::itemText(int index) const

Returns the text for the given index in the combobox.

参见 setItemText().

[virtual protected] void QComboBox::keyPressEvent(QKeyEvent *e)

重新实现 QWidget::keyPressEvent().

[virtual protected] void QComboBox::keyReleaseEvent(QKeyEvent *e)

重新实现 QWidget::keyReleaseEvent().

QLineEdit *QComboBox::lineEdit() const

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.

参见 setLineEdit().

[virtual] QSize QComboBox::minimumSizeHint() const

重新实现 QWidget::minimumSizeHint().

QAbstractItemModel *QComboBox::model() const

Returns the model used by the combobox.

参见 setModel().

[virtual protected] void QComboBox::mousePressEvent(QMouseEvent *e)

重新实现 QWidget::mousePressEvent().

[virtual protected] void QComboBox::mouseReleaseEvent(QMouseEvent *e)

重新实现 QWidget::mouseReleaseEvent().

[virtual protected] void QComboBox::paintEvent(QPaintEvent *e)

重新实现 QWidget::paintEvent().

void QComboBox::removeItem(int index)

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.

[virtual protected] void QComboBox::resizeEvent(QResizeEvent *e)

重新实现 QWidget::resizeEvent().

QModelIndex QComboBox::rootModelIndex() const

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

参见 setRootModelIndex().

void QComboBox::setCompleter(QCompleter *completer)

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 QCompleter that performs case insensitive inline completion is automatically created.

Note: The completer is removed when the editable property becomes false.

This function was introduced in Qt 4.2.

参见 completer().

[slot] void QComboBox::setEditText(const QString &text)

Sets the text in the combobox's text edit.

void QComboBox::setItemData(int index, const QVariant &value, int role = Qt::UserRole)

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

参见 itemData().

void QComboBox::setItemDelegate(QAbstractItemDelegate *delegate)

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

参见 itemDelegate().

void QComboBox::setItemIcon(int index, const QIcon &icon)

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

参见 itemIcon().

void QComboBox::setItemText(int index, const QString &text)

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

参见 itemText().

void QComboBox::setLineEdit(QLineEdit *edit)

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

The combo box takes ownership of the line edit.

参见 lineEdit().

void QComboBox::setModel(QAbstractItemModel *model)

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

参见 model() and clear().

void QComboBox::setRootModelIndex(const QModelIndex &index)

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

参见 rootModelIndex().

void QComboBox::setValidator(const QValidator *validator)

Sets the validator to use instead of the current validator.

Note: The validator is removed when the editable property becomes false.

参见 validator().

void QComboBox::setView(QAbstractItemView *itemView)

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.

参见 view().

[virtual protected] void QComboBox::showEvent(QShowEvent *e)

重新实现 QWidget::showEvent().

[virtual] void 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 hidePopup() to reset the internal state.

参见 hidePopup().

[virtual] QSize QComboBox::sizeHint() const

重新实现 QWidget::sizeHint().

This implementation caches the size hint to avoid resizing when the contents change dynamically. To invalidate the cached value change the sizeAdjustPolicy.

const QValidator *QComboBox::validator() const

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

参见 setValidator() and editable.

QAbstractItemView *QComboBox::view() const

Returns the list view used for the combobox popup.

参见 setView().

[virtual protected] void QComboBox::wheelEvent(QWheelEvent *e)

重新实现 QWidget::wheelEvent().