ComboBox 下拉框的应用

1.控件位置

Input Widgets→ComboBox

2.控件介绍

ComboBox控件(组合框)的样式如图3-63所示。Qt Creator的ComboBox和Qt Designer的ComboBox样式有些不同。


3.控件设置选项

在ComboBox控件的properties选项中,一般常对以下选项进行设置。

name:该控件对应源代码中的名称;

font:设置显示的字体;

editable:用来获取或设置一个值,以确定ComboBox的编辑框是否可编辑。值为true时为可编辑,值为false时为只读;

currentIndex:当前选项的索引;

maxVisibleItems:ComboBox可见的最大项目数;

maxCount:ComboBox的最大项目数。

4.常用成员函数

1) QComboBox::QComboBox ( QWidget *parent = 0, const char *name = 0 )

构造一个名称为name、父对象为parent的ComboBox。

2) QComboBox::QComboBox ( bool rw, QWidget *parent = 0, const char *name = 0 )

构造一个名称为name、父对象为parent的ComboBox。如果rw是true,则编辑栏可编辑;否则只能选择ComboBox项目之一。

3) void QComboBox::clear () [slot]

删除ComboBox中的所有项目。

4) int QComboBox::count () const

返回ComboBox中的项目数。

5) int QComboBox::currentItem () const

返回ComboBox中当前项目的索引。

6) QString QComboBox::currentText () const

返回组合框的当前项目文本。

7) void QComboBox::insertItem ( const QString & t, int index = -1 )

在索引index处,插入一个文本为t的项目。如果index是负数,该项目将被追加到末尾。

8) void QComboBox::insertItem ( const QPixmap & pixmap, int index = -1 )

在索引index处,插入一个图标为pixmap的项目。如果index是负数,该项目将被追加到末尾。

9) void QComboBox::insertItem ( const QPixmap & pixmap, const QString & text, int index = -1 )

在索引index处,插入一个文本为t和图标为pixmap的项目。如果index是负数,该项目将被追加到末尾。

10) QString QComboBox::currentText () const

返回组合框的当前项目文本。

11) void QComboBox::removeItem ( int index )

删除索引index处项目。

12) void QComboBox::setCurrentItem ( int index ) [virtual]

把索引index处的项目设为当前项目。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值