ComboBox控件介绍(有用啊)

论坛 期权论坛 脚本     
匿名技术用户   2021-1-14 14:39   246   0

ComboBox控件

1.控件位置

Input Widgets→ComboBox

2.控件介绍

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

图3-63 ComboBox控件

3.控件设置选项

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

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

font:设置显示的字体;

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

currentIndex:当前选项的索引;

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

maxCount:ComboBox的最大项目数。

4.常用成员函数

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

构造一个名称为name、父对象为parent的ComboBox。
 
  1. 2) QComboBox::QComboBox ( bool rw, QWidget *parent = 0, const char *name = 0 )

构造一个名称为name、父对象为parent的ComboBox。如果rw是true,则编辑栏可编辑;否则只能选择ComboBox项目之一。
 
  1. 3) void QComboBox::clear () [slot]

删除ComboBox中的所有项目。
 
  1. 4) int QComboBox::count () const

返回ComboBox中的项目数。
 
  1. 5) int QComboBox::currentItem () const

返回ComboBox中当前项目的索引。
 
  1. 6) QString QComboBox::currentText () const

返回组合框的当前项目文本。
 
  1. 7) void QComboBox::insertItem ( const QString & t, int index = -1 )

在索引index处,插入一个文本为t的项目。如果index是负数,该项目将被追加到末尾。
 
  1. 8) void QComboBox::insertItem ( const QPixmap & pixmap, int index = -1 )

在索引index处,插入一个图标为pixmap的项目。如果index是负数,该项目将被追加到末尾。
 
  1. 9) void QComboBox::insertItem ( const QPixmap & pixmap, const QString & text, int index = -1 )

在索引index处,插入一个文本为t和图标为pixmap的项目。如果index是负数,该项目将被追加到末尾。
 
  1. 10) QString QComboBox::currentText () const

返回组合框的当前项目文本。
 
  1. 11) void QComboBox::removeItem ( int index )

删除索引index处项目。
 
  1. 12) void QComboBox::setCurrentItem ( int index ) [virtual]

把索引index处的项目设为当前项目。
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP