当前位置: 代码迷 >> 综合 >> QComboBox 使用
  详细解决方案

QComboBox 使用

热度:30   发布时间:2024-02-23 21:21:14.0

QComboBox

  • QComboBox Class类简介
  • Public Types
  • Public Functions

QComboBox Class类简介

The QComboBox widget is a combined button and popup list.
Header:#include
qmake:QT += widgets
Inherits:QWidget
Inherited By:QFontComboBox
List of all members, including inherited members(所有成员的列表,包括继承的成员)
Obsolete members (过时的成员)

Public Types

enum InsertPolicy { NoInsert, InsertAtTop, InsertAtCurrent, InsertAtBottom, …, InsertAlphabetically }
This enum specifies what the QComboBox should do when a new string is entered by the user.
这个枚举指定当用户输入一个新字符串时QComboBox应该做什么。
Constant 常量 Value 值 Description 说明
QComboBox::NoInsert 0 The string will not be inserted into the combobox.
QComboBox::InsertAtTop 1 The string will be inserted as the first item in the combobox.
QComboBox::InsertAtCurrent 2 The current item will be replaced by the string.
QComboBox::InsertAtBottom 3 The string will be inserted after the last item in the combobox.
QComboBox::InsertAfterCurrent 4 The string is inserted after the current item in the combobox.
QComboBox::InsertBeforeCurrent 5 The string is inserted before the current item in the combobox.
QComboBox::InsertAlphabetically 6 The string is inserted in the alphabetic order in the combobox.
enum SizeAdjustPolicy { AdjustToContents, AdjustToContentsOnFirstShow, AdjustToMinimumContentsLength, AdjustToMinimumContentsLengthWithIcon }
This enum specifies how the size hint of the QComboBox should adjust when new content is added or content changes.
这个枚举指定当添加新内容或内容更改时QComboBox的大小提示应该如何调整。
Constant Value Description
QComboBox::AdjustToContents 0 The combobox will always adjust to the contents
QComboBox::AdjustToContentsOnFirstShow 1 The combobox will adjust to its contents the first time it is shown.
QComboBox::AdjustToMinimumContentsLength 2 Use AdjustToContents or AdjustToContentsOnFirstShow instead.
QComboBox::AdjustToMinimumContentsLengthWithIcon 3 The combobox will adjust to minimumContentsLength plus space for an

Public Functions

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 =
int findText(const QString &text, Qt::MatchFlags flags = static_castQt::MatchFlags (
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
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