QT QComboBox(4)使用

68 篇文章 66 订阅 ¥299.90 ¥99.00

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

enumInsertPolicy { 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::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.
enumSizeAdjustPolicy { 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的大小提示应该如何调整。
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

Public Functions

QComboBox(QWidget *parent = Q_NULLPTR)
~QComboBox()
voidaddItem(const QString &text, const QVariant &userData = QVariant())
voidaddItem(const QIcon &icon, const QString &text, const QVariant &userData = QVariant())
voidaddItems(const QStringList &texts)
QCompleter *completer() const
intcount() const
QVariantcurrentData(int role = Qt::UserRole) const
intcurrentIndex() const
QStringcurrentText() const
boolduplicatesEnabled() const
intfindData(const QVariant &data, int role = Qt::UserRole, Qt::MatchFlags flags =
intfindText(const QString &text, Qt::MatchFlags flags = static_castQt::MatchFlags (
boolhasFrame() const
virtual voidhidePopup()
QSizeiconSize() const
voidinsertItem(int index, const QString &text, const QVariant &userData = QVariant())
voidinsertItem(int index, const QIcon &icon, const QString &text, const QVariant &userData
voidinsertItems(int index, const QStringList &list)
InsertPolicyinsertPolicy() const
voidinsertSeparator(int index)
boolisEditable() const
QVariantitemData(int index, int role = Qt::UserRole) const
QAbstractItemDelegate *itemDelegate() const
QIconitemIcon(int index) const
QStringitemText(int index) const 某下标对应的内容
QLineEdit *lineEdit() const
intmaxCount() const
intmaxVisibleItems() const
intminimumContentsLength() const
QAbstractItemModel *model() const
intmodelColumn() const
voidremoveItem(int index)
QModelIndexrootModelIndex() const
voidsetCompleter(QCompleter *completer)
voidsetDuplicatesEnabled(bool enable)
voidsetEditable(bool editable)
voidsetFrame(bool)
voidsetIconSize(const QSize &size)
voidsetInsertPolicy(InsertPolicy policy)
voidsetItemData(int index, const QVariant &value, int role = Qt::UserRole)
voidsetItemDelegate(QAbstractItemDelegate *delegate)
voidsetItemIcon(int index, const QIcon &icon)
voidsetItemText(int index, const QString &text)
voidsetLineEdit(QLineEdit *edit)
voidsetMaxCount(int max)
voidsetMaxVisibleItems(int maxItems)
voidsetMinimumContentsLength(int characters)
voidsetModel(QAbstractItemModel *model)
voidsetModelColumn(int visibleColumn)
voidsetRootModelIndex(const QModelIndex &index)
voidsetSizeAdjustPolicy(SizeAdjustPolicy policy)
voidsetValidator(const QValidator *validator)
voidsetView(QAbstractItemView *itemView)
virtual voidshowPopup()
SizeAdjustPolicysizeAdjustPolicy() const
const QValidator *validator() const
QAbstractItemView *view() const

添加项目

添加一项

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.

comboBox ->addItem( "value");

添加多项

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.

QStringList list;
list << "value1" << "value2"<<"value3"<<;
comboBox ->addItems(list);

QT QComboBox(3)隐藏下拉小箭头
QT QComboBox(5)隐藏某一项下拉信息

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:书香水墨 设计师:CSDN官方博客 返回首页
评论

打赏作者

光顶术士

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值