QComboBox Class ReferenceThe QComboBox widget is a combined button and popup list. Далее... #include <QComboBox> Унаследован от: QWidget. Inherited by: QFontComboBox. Открытые типы
Свойства
Открытые функции
Переопределённые открытые функции
Открытые слоты
Сигналы
Защищенные функции
Переопределённые защищённые функции
Дополнительные унаследованные члены
Подробное описание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 selects 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. Note that you cannot alter the SelectionMode of the view(), e.g., by using setSelectionMode(). See also QLineEdit, QSpinBox, QRadioButton, QButtonGroup, and GUI Design Handbook: Combo Box, Drop-Down List Box. Описание типов-членовenum QComboBox::InsertPolicyThis enum specifies what the QComboBox should do when a new string is entered by the user.
enum QComboBox::SizeAdjustPolicyThis enum specifies how the size hint of the QComboBox should adjust when new content is added or content changes.
Описание свойствcount : const intThis property holds the number of items in the combobox. By default, for an empty combo box, this property has a value of 0. Функции доступа:
currentIndex : intThis property holds the index of the current item in the combobox. The current index can change when inserting or removing items. By default, for an empty combo box or a combo box in which no current item is set, this property has a value of -1. Функции доступа:
Уведомляющий сигнал:
currentText : const QStringThis property holds the current text. If the combo box is editable, the current text is the value displayed by the line edit. Otherwise, it is the value of the current item or an empty string if the combo box is empty or no current item is set. Функции доступа:
Смотрите также editable. duplicatesEnabled : boolThis 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. By default, this property is false (duplicates are not allowed). Функции доступа:
editable : boolThis property holds whether the combo box can be edited by the user. По умолчанию это свойство равно false. The effect of editing depends on the insert policy. Функции доступа:
See also InsertPolicy. frame : boolThis 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. Функции доступа:
iconSize : QSizeThis 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. Функции доступа:
insertPolicy : InsertPolicyThis 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. Функции доступа:
See also InsertPolicy. maxCount : intThis 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. By default, this property's value is derived from the highest signed integer available (typically 2147483647). Функции доступа:
maxVisibleItems : intThis property holds the maximum allowed size on screen of the combo box, measured in items. By default, this property has a value of 10. Note: This property is ignored for non-editable comboboxes in styles that returns true for QStyle::SH_ComboBox_Popup such as the Mac style or the Gtk+ Style. Функции доступа:
minimumContentsLength : intThis property holds the minimum number of characters that should fit into the combobox. Значение по умолчанию равно 0. If this property is set to a positive value, the minimumSizeHint() and sizeHint() take it into account. Функции доступа:
See also sizeAdjustPolicy. modelColumn : intЭто свойство содержит номер отображаемого столбца в модели. If set prior to populating the combo box, the pop-up view will not be affected and will show the first column (using this property's default value). По умолчанию это свойство имеет значение 0. Функции доступа:
sizeAdjustPolicy : SizeAdjustPolicyThis property holds the policy describing how the size of the combobox changes when the content changes. The default value is AdjustToContentsOnFirstShow. Функции доступа:
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 the user chooses an item in the combobox. The item's index is passed. Note that this signal is sent even when the choice is not changed. If you need to know when the choice actually changes, use signal currentIndexChanged(). void QComboBox::activated ( const QString & text ) [signal]This signal is sent when the user chooses an item in the combobox. The item's text is passed. Note that this signal is sent even when the choice is not changed. If you need to know when the choice actually changes, use signal currentIndexChanged(). 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 (stored in the Qt::UserRole). Элемент добавляется в список существующих элементов. 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). Элемент добавляется в список существующих элементов. 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::changeEvent ( QEvent * e ) [virtual protected]Переопределено от QWidget::changeEvent(). 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 () constReturns the completer that is used to auto complete text input for the combobox. Эта функция была введена в Qt 4.2. See also setCompleter() and editable. void QComboBox::contextMenuEvent ( QContextMenuEvent * e ) [virtual protected]Переопределено из QWidget::contextMenuEvent(). 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 passed or -1 if the combobox becomes empty or the currentIndex was reset. Эта функция была введена в Qt 4.1. void QComboBox::currentIndexChanged ( const QString & text ) [signal]This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. The item's text is passed. Эта функция была введена в 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. bool QComboBox::event ( QEvent * event ) [virtual]Переопределено от QObject::event(). int QComboBox::findData ( const QVariant & data, int role = Qt::UserRole, Qt::MatchFlags flags = static_cast<Qt::MatchFlags> ( Qt::MatchExactly | Qt::MatchCaseSensitive ) ) constReturns 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 = static_cast<Qt::MatchFlags> ( Qt::MatchExactly | Qt::MatchCaseSensitive ) ) constReturns 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::focusInEvent ( QFocusEvent * e ) [virtual protected]Переопределено из QWidget::focusInEvent(). void QComboBox::focusOutEvent ( QFocusEvent * e ) [virtual protected]Переопределено из QWidget::focusOutEvent(). void QComboBox::hideEvent ( QHideEvent * e ) [virtual protected]Переопределено из QWidget::hideEvent(). void QComboBox::hidePopup () [virtual]Hides the list of items in the combobox if it is currently visible and resets the internal state, so that if the custom pop-up was shown inside the reimplemented showPopup(), then you also need to reimplement the hidePopup() function to hide your custom pop-up and call the base class implementation to reset the internal state whenever your custom pop-up widget is hidden. See also showPopup(). 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 passed. void QComboBox::highlighted ( const QString & text ) [signal]This signal is sent when an item in the combobox popup list is highlighted by the user. The item's text is passed. 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. Смотрите также QStyleOption::initFrom(). void QComboBox::inputMethodEvent ( QInputMethodEvent * e ) [virtual protected]Переопределено из QWidget::inputMethodEvent(). QVariant QComboBox::inputMethodQuery ( Qt::InputMethodQuery query ) const [virtual protected]Переопределено из QWidget::inputMethodQuery(). void QComboBox::insertItem ( int index, const QString & text, const QVariant & userData = QVariant() )Inserts the text and userData (stored in the Qt::UserRole) 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. Смотрите также insertItems(). void QComboBox::insertItem ( int index, const QIcon & icon, const QString & text, const QVariant & userData = QVariant() )Inserts the icon, text and userData (stored in the Qt::UserRole) 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. Смотрите также 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(). void QComboBox::insertSeparator ( int index )Inserts a separator item 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. Эта функция была введена в Qt 4.4. See also insertItem(). QVariant QComboBox::itemData ( int index, int role = Qt::UserRole ) constReturns 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 () constReturns the item delegate used by the popup list view. See also setItemDelegate(). QIcon QComboBox::itemIcon ( int index ) constReturns the icon for the given index in the combobox. See also setItemIcon(). QString QComboBox::itemText ( int index ) constReturns the text for the given index in the combobox. See also setItemText(). void QComboBox::keyPressEvent ( QKeyEvent * e ) [virtual protected]Переопределено от QWidget::keyPressEvent(). void QComboBox::keyReleaseEvent ( QKeyEvent * e ) [virtual protected]Переопределено из QWidget::keyReleaseEvent(). QLineEdit * QComboBox::lineEdit () constReturns 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(). QSize QComboBox::minimumSizeHint () const [virtual]Переопределено от QWidget::minimumSizeHint(). QAbstractItemModel * QComboBox::model () constReturns the model used by the combobox. See also setModel(). void QComboBox::mousePressEvent ( QMouseEvent * e ) [virtual protected]Переопределено из QWidget::mousePressEvent(). void QComboBox::mouseReleaseEvent ( QMouseEvent * e ) [virtual protected]Переопределено из QWidget::mouseReleaseEvent(). void QComboBox::paintEvent ( QPaintEvent * e ) [virtual protected]Переопределено от QWidget::paintEvent(). 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. This function does nothing if index is out of range. void QComboBox::resizeEvent ( QResizeEvent * e ) [virtual protected]Переопределено от QWidget::resizeEvent(). QModelIndex QComboBox::rootModelIndex () constReturns 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. Эта функция была введена в 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(). 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::showEvent ( QShowEvent * e ) [virtual protected]Переопределено от QWidget::showEvent(). void QComboBox::showPopup () [virtual]Displays the list of items in the combobox. If the list is empty then the no items will be shown. If you reimplement this function to show a custom pop-up, make sure you call hidePopup() to reset the internal state. See also hidePopup(). QSize QComboBox::sizeHint () const [virtual]Переопределено от QWidget::sizeHint(). This implementation caches the size hint to avoid resizing when the contents change dynamically. To invalidate the cached value change the sizeAdjustPolicy. const QValidator * QComboBox::validator () constReturns the validator that is used to constrain text input for the combobox. See also setValidator() and editable. QAbstractItemView * QComboBox::view () constReturns the list view used for the combobox popup. See also setView(). void QComboBox::wheelEvent ( QWheelEvent * e ) [virtual protected]Переопределено из QWidget::wheelEvent(). |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |