ComboBox QML Type
A combined button and popup list taking minimal space. More...
Import Statement: | import QtQuick.Controls 2.0 |
Since: | Qt 5.7 |
Inherits: |
Properties
- count : int
- currentIndex : int
- currentText : string
- delegate : Component
- displayText : string
- highlightedIndex : int
- indicator : Item
- model : model
- popup : Popup
- pressed : bool
- textRole : string
Signals
- void activated(int index)
- void highlighted(int index)
Methods
- void decrementCurrentIndex()
- int find(string text, flags)
- void incrementCurrentIndex()
- string textAt(int index)
Detailed Description
ComboBox is a combined button and popup list. It provides a means of presenting a list of options to the user in a way that takes up the minimum amount of screen space.
ComboBox is populated with a data model. The data model is commonly a JavaScript array, a ListModel or an integer, but also other types of data models are supported.
ComboBox { model: ["First", "Second", "Third"] }
ComboBox is able to visualize standard data models that provide the modelData
role:
- models that have only one role
- models that do not have named roles (JavaScript array, integer)
When using models that have multiple named roles, ComboBox must be configured to use a specific text role for its display text and delegate instances.
ComboBox { textRole: "key" model: ListModel { ListElement { key: "First"; value: 123 } ListElement { key: "Second"; value: 456 } ListElement { key: "Third"; value: 789 } } }
Note: If ComboBox is assigned a data model that has multiple named roles, but textRole is not defined, ComboBox is unable to visualize it and throws a ReferenceError: modelData is not defined
.
See also Customizing ComboBox and Input Controls.
Property Documentation
This property holds the index of the current item in the combo box.
See also activated() and currentText.
This property holds the text of the current item in the combo box.
See also currentIndex, displayText, and textRole.
delegate : Component |
This property holds a delegate that presents an item in the combo box popup.
See also ItemDelegate and Customizing ComboBox.
This property holds the text that is displayed on the combo box button.
By default, the display text presents the current selection. That is, it follows the text of the current item. However, the default display text can be overridden with a custom value.
ComboBox { currentIndex: 1 displayText: "Size: " + currentText model: ["S", "M", "L"] }
See also currentText and textRole.
This property holds the index of the highlighted item in the combo box popup list.
See also highlighted() and currentIndex.
indicator : Item |
This property holds the drop indicator item.
model : model |
This property holds the model providing data for the combo box.
ComboBox { textRole: "key" model: ListModel { ListElement { key: "First"; value: 123 } ListElement { key: "Second"; value: 456 } ListElement { key: "Third"; value: 789 } } }
See also textRole and Data Models.
popup : Popup |
This property holds the popup.
See also Customizing ComboBox.
This property holds the model role used for populating the combo box.
See also model, currentText, and displayText.
Signal Documentation
This signal is emitted when the item at index is activated by the user.
See also currentIndex.
This signal is emitted when the item at index in the popup list is highlighted by the user.
See also highlightedIndex.
Method Documentation
Decrements the current index of the combo box, or the highlighted index if the popup list when it is visible.
See also currentIndex and highlightedIndex.
Returns the index of the specified text, or -1
if no match is found.
The way the search is performed is defined by the specified match flags. By default, combo box performs case sensitive exact matching (Qt.MatchExactly
). All other match types are case-insensitive unless the Qt.MatchCaseSensitive
flag is also specified.
Constant | Description |
---|---|
Qt.MatchExactly | The search term matches exactly (default). |
Qt.MatchRegExp | The search term matches as a regular expression. |
Qt.MatchWildcard | The search term matches using wildcards. |
Qt.MatchFixedString | The search term matches as a fixed string. |
Qt.MatchStartsWith | The search term matches the start of the item. |
Qt.MatchEndsWidth | The search term matches the end of the item. |
Qt.MatchContains | The search term is contained in the item. |
Qt.MatchCaseSensitive | The search is case sensitive. |
See also textRole.
Increments the current index of the combo box, or the highlighted index if the popup list when it is visible.
See also currentIndex and highlightedIndex.
Returns the text for the specified index, or an empty string if the index is out of bounds.
See also textRole.