Qt:Документация 4.3.2/qcombobox

Материал из Wiki.crossplatform.ru

Версия от 10:00, 14 ноября 2008; Root (Обсуждение | вклад)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] QComboBox Class Reference
[модуль QtGui ]

The QComboBox widget is a combined button and popup list. More...

 #include <QComboBox>

Inherits QWidget.

Inherited by QFontComboBox.

[править] Открытые типы

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

[править] Свойства

  • 56 свойства унаследованных от QWidget
  • 1 свойство унаследованное от QObject

[править] Открытые функции

  • 201 открытых функций унаследованных от QWidget
  • 29 открытых функций унаследованных от QObject
  • 12 открытых функций унаследованных от QPaintDevice

[править] Открытые слоты

  • 19 открытых слотов унаследованных от QWidget
  • 1 открытый слот унаследованный от QObject

[править] Сигналы

  • 1 сигнал унаследованный от QWidget
  • 1 сигнал унаследованный от QObject

[править] Защищенные функции

  • 38 защищенных функций унаследованных от QWidget
  • 7 защищенных функций унаследованных от QObject
  • 1 защищенная функция унаследованна от QPaintDevice

[править] Дополнительные унаследованные члены

  • 4 статических открытых члена унаследованных от QWidget
  • 5 статических открытых члена унаследованных от QObject
  • 1 защищенный слот унаследованный от QWidget

[править] Подробное описание

The QComboBox widget is a combined button and popup list.

A QComboBox provides a means of presenting a list of options to the user in a way that takes up the minimum amount of screen space.

A combobox is a selection widget that displays the current item, and can pop up a list of selectable items. A combobox may be editable, allowing the user to modify each item in the list.

Comboboxes can contain pixmaps as well as strings; the insertItem() and setItemText() functions are suitably overloaded. For editable comboboxes, the function clearEditText() is provided, to clear the displayed string without changing the combobox's contents.

There are two signals emitted if the current item of a combobox changes, currentIndexChanged() and activated(). currentIndexChanged() is always emitted regardless if the change was done programmatically or by user interaction, while activated() is only emitted when the change is caused by user interaction. The highlighted() signal is emitted when the user highlights an item in the combobox popup list. All three signals exist in two versions, one with a QString argument and one with an int argument. If the user selectes or highlights a pixmap, only the int signals are emitted. Whenever the text of an editable combobox is changed the editTextChanged() signal is emitted.

When the user enters a new string in an editable combobox, the widget may or may not insert it, and it can insert it in several locations. The default policy is is AtBottom but you can change this using setInsertPolicy().

It is possible to constrain the input to an editable combobox using QValidator; see setValidator(). By default, any input is accepted.

A combobox can be populated using the insert functions, insertItem() and insertItems() for example. Items can be changed with setItemText(). An item can be removed with removeItem() and all items can be removed with clear(). The text of the current item is returned by currentText(), and the text of a numbered item is returned with text(). The current item can be set with setCurrentIndex(). The number of items in the combobox is returned by count(); the maximum number of items can be set with setMaxCount(). You can allow editing using setEditable(). For editable comboboxes you can set auto-completion using setCompleter() and whether or not the user can add duplicates is set with setDuplicatesEnabled().

QComboBox uses the model/view framework for its popup list and to store its items. By default a QStandardItemModel stores the items and a QListView subclass displays the popuplist. You can access the model and view directly (with model() and view()), but QComboBox also provides functions to set and get item data (e.g., setItemData() and itemText()). You can also set a new model and view (with setModel() and setView()). For the text and icon in the combobox label, the data in the model that has the Qt::DisplayRole and Qt::DecorationRole is used.

center

See also QLineEdit, QSpinBox, QRadioButton, QButtonGroup, and 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.


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 QComboBox::SizeAdjustPolicy

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


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 show.
QComboBox::AdjustToMinimumContentsLength 2 Use AdjustToContents or AdjustToContentsOnFirstShow instead.
QComboBox::AdjustToMinimumContentsLengthWithIcon 3 The 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.

Функции доступа:

  • int count () const

[править]
currentIndex : int

This property holds the index of the current item in the combobox. The index can change when inserting or removing items. Returns -1 if no current item is set or the combobox is empty.

Функции доступа:

  • int currentIndex () const
  • void setCurrentIndex ( int index )

[править]
currentText : const QString

This property holds the text of the current item.

Функции доступа:

  • QString currentText () const

[править]
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.

Функции доступа:

  • bool duplicatesEnabled () const
  • void setDuplicatesEnabled ( bool enable )

[править]
editable : bool

This property holds whether the combobox can be edited by the user.

Функции доступа:

  • bool isEditable () const
  • void setEditable ( bool editable )

[править]
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 AtBottom, indicating that new items will appear at the bottom of the list of items.

Функции доступа:

  • InsertPolicy insertPolicy () const
  • void setInsertPolicy ( InsertPolicy policy )

See also 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.

Функции доступа:

  • int maxCount () const
  • void setMaxCount ( int max )

[править]
maxVisibleItems : int

This property holds the maximum allowed size on screen of the combobox.

This property is ignored for non-editable comboboxes in Mac 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 )

See also sizeAdjustPolicy.

[править]
modelColumn : int

This property holds the column in the model that is visible.

If set prior to populating the combobox, the popup view will not be affected and will show the first column.

Функции доступа:

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

See also SizeAdjustPolicy.


[править] Описание функций-членов

[править]
QComboBox::QComboBox ( QWidget * parent = 0 )

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

[править]
QComboBox::~QComboBox ()

Destroys the combobox.

[править]
void QComboBox::activated ( int index ) [signal]

This signal is sent when an item in the combobox is activated by the user. The item's index is given.

[править]
void QComboBox::activated ( const QString & text ) [signal]

This is an overloaded member function, provided for convenience.

This signal is sent when an item in the combobox is activated by the user. The item's text is given.

[править]
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. The item is appended to the list of existing items.

[править]
void QComboBox::addItem ( const QIcon & icon, const QString & text, const QVariant & userData = QVariant() )

This is an overloaded member function, provided for convenience.

Adds an item to the combobox with the given icon and text, and containing the specified userData. 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.

[править]
void QComboBox::clear () [slot]

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.

[править]
void QComboBox::clearEditText () [slot]

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.

See also setCompleter() and editable.

[править]
void QComboBox::currentIndexChanged ( int index ) [signal]

This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. The item's index is given or -1 if the combobox becomes empty or the currentIndex was reset.

This function was introduced in Qt 4.1.

[править]
void QComboBox::currentIndexChanged ( const QString & text ) [signal]

This is an overloaded member function, provided for convenience.

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

This function was introduced in Qt 4.1.

[править]
void QComboBox::editTextChanged ( const QString & text ) [signal]

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

[править]
int QComboBox::findData ( const QVariant & data, int role = Qt::UserRole, Qt::MatchFlags flags = 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 = 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.

[править]
void QComboBox::hidePopup () [virtual]

Hides the list of items in the combobox if it is currently visible; otherwise this function does nothing.

[править]
void QComboBox::highlighted ( int index ) [signal]

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

[править]
void QComboBox::highlighted ( const QString & text ) [signal]

This is an overloaded member function, provided for convenience.

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

[править]
void QComboBox::initStyleOption ( QStyleOptionComboBox * option ) const [protected]

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.

See also QStyleOption::initFrom().

[править]
void QComboBox::insertItem ( int index, const QString & text, const QVariant & userData = QVariant() )

Inserts the text and userData 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.

See also insertItems().

[править]
void QComboBox::insertItem ( int index, const QIcon & icon, const QString & text, const QVariant & userData = QVariant() )

This is an overloaded member function, provided for convenience.

Inserts the icon, text and userData 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.

See also 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.

See also 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.

See also setItemData().

[править]
QAbstractItemDelegate * QComboBox::itemDelegate () const

Returns the item delegate used by the popup list view.

See also setItemDelegate().

[править]
QIcon QComboBox::itemIcon ( int index ) const

Returns the icon for the given index in the combobox.

See also setItemIcon().

[править]
QString QComboBox::itemText ( int index ) const

Returns the text for the given index in the combobox.

See also setItemText().

[править]
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.

See also setLineEdit().

[править]
QAbstractItemModel * QComboBox::model () const

Returns the model used by the combobox.

See also setModel().

[править]
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.

[править]
QModelIndex QComboBox::rootModelIndex () const

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

See also 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.

This function was introduced in Qt 4.2.

See also completer().

[править]
void QComboBox::setEditText ( const QString & text ) [slot]

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.

See also 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.

See also itemDelegate().

[править]
void QComboBox::setItemIcon ( int index, const QIcon & icon )

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

See also itemIcon().

[править]
void QComboBox::setItemText ( int index, const QString & text )

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

See also 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.

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

See also model() and clear().

[править]
void QComboBox::setRootModelIndex ( const QModelIndex & index )

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

See also rootModelIndex().

[править]
void QComboBox::setValidator ( const QValidator * validator )

Sets the validator to use instead of the current validator.

See also 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.

See also view().

[править]
void QComboBox::showPopup () [virtual]

Displays the list of items in the combobox. If the list is empty then the no items will be shown.

[править]
const QValidator * QComboBox::validator () const

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

See also setValidator() and editable.

[править]
QAbstractItemView * QComboBox::view () const

Returns the list view used for the combobox popup.

See also setView().


Copyright © 2007 Trolltech Trademarks
Qt 4.3.2