<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qquickcombobox.cpp --> <title>ComboBox QML Type | Qt Labs Controls 5.6</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> window.onload = function(){document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");}; </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.6</td><td ><a href="qtlabscontrols-index.html">Qt Labs Controls</a></td><td ><a href="qt-labs-controls-qmlmodule.html">QML Types</a></td><td >ComboBox QML Type</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.6.2 Reference Documentation</td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#properties">Properties</a></li> <li class="level1"><a href="#signals">Signals</a></li> <li class="level1"><a href="#methods">Methods</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">ComboBox QML Type</h1> <span class="subtitle"></span> <!-- $$$ComboBox-brief --> <p>A combo box control. <a href="#details">More...</a></p> <!-- @@@ComboBox --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Import Statement:</td><td class="memItemRight bottomAlign"> import Qt.labs.controls 1.0</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <p><a href="qml-qt-labs-controls-control.html">Control</a></p> </td></tr></table></div><ul> <li><a href="qml-qt-labs-controls-combobox-members.html">List of all members, including inherited members</a></li> </ul> <a name="properties"></a> <h2 id="properties">Properties</h2> <ul> <li class="fn"><b><b><a href="qml-qt-labs-controls-combobox.html#count-prop">count</a></b></b> : int</li> <li class="fn"><b><b><a href="qml-qt-labs-controls-combobox.html#currentIndex-prop">currentIndex</a></b></b> : int</li> <li class="fn"><b><b><a href="qml-qt-labs-controls-combobox.html#currentText-prop">currentText</a></b></b> : string</li> <li class="fn"><b><b><a href="qml-qt-labs-controls-combobox.html#delegate-prop">delegate</a></b></b> : Component</li> <li class="fn"><b><b><a href="qml-qt-labs-controls-combobox.html#displayText-prop">displayText</a></b></b> : string</li> <li class="fn"><b><b><a href="qml-qt-labs-controls-combobox.html#highlightedIndex-prop">highlightedIndex</a></b></b> : int</li> <li class="fn"><b><b><a href="qml-qt-labs-controls-combobox.html#model-prop">model</a></b></b> : model</li> <li class="fn"><b><b><a href="qml-qt-labs-controls-combobox.html#popup-prop">popup</a></b></b> : Popup</li> <li class="fn"><b><b><a href="qml-qt-labs-controls-combobox.html#pressed-prop">pressed</a></b></b> : bool</li> <li class="fn"><b><b><a href="qml-qt-labs-controls-combobox.html#textRole-prop">textRole</a></b></b> : string</li> </ul> <a name="signals"></a> <h2 id="signals">Signals</h2> <ul> <li class="fn">void <b><b><a href="qml-qt-labs-controls-combobox.html#activated-signal">activated</a></b></b>(int <i>index</i>)</li> <li class="fn">void <b><b><a href="qml-qt-labs-controls-combobox.html#highlighted-signal">highlighted</a></b></b>(int <i>index</i>)</li> </ul> <a name="methods"></a> <h2 id="methods">Methods</h2> <ul> <li class="fn">int <b><b><a href="qml-qt-labs-controls-combobox.html#find-method">find</a></b></b>(string <i>text</i>, <i>flags</i>)</li> <li class="fn">string <b><b><a href="qml-qt-labs-controls-combobox.html#textAt-method">textAt</a></b></b>(int <i>index</i>)</li> </ul> <!-- $$$ComboBox-description --> <a name="details"></a> <h2 id="details">Detailed Description</h2> </p> <p class="centerAlign"><img src="images/qtlabscontrols-combobox.png" alt="" /></p><p><a href="qml-qt-labs-controls-combobox.html">ComboBox</a> 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.</p> <p><a href="qml-qt-labs-controls-combobox.html">ComboBox</a> 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.</p> <pre class="cpp"> ComboBox { model: <span class="operator">[</span><span class="string">"First"</span><span class="operator">,</span> <span class="string">"Second"</span><span class="operator">,</span> <span class="string">"Third"</span><span class="operator">]</span> } </pre> <p><a href="qml-qt-labs-controls-combobox.html">ComboBox</a> is able to visualize standard data models that provide the <code>modelData</code> role:</p> <ul> <li>models that have only one role</li> <li>models that do not have named roles (JavaScript array, integer)</li> </ul> <p>When using models that have multiple named roles, <a href="qml-qt-labs-controls-combobox.html">ComboBox</a> must be configured to use a specific <a href="qml-qt-labs-controls-combobox.html#textRole-prop">text role</a> for its <a href="qml-qt-labs-controls-combobox.html#displayText-prop">display text</a> and <a href="qtlabscontrols-customize.html#delegate">delegate</a> instances.</p> <pre class="cpp"> ComboBox { textRole: <span class="string">"key"</span> model: ListModel { ListElement { key: <span class="string">"First"</span>; value: <span class="number">123</span> } ListElement { key: <span class="string">"Second"</span>; value: <span class="number">456</span> } ListElement { key: <span class="string">"Third"</span>; value: <span class="number">789</span> } } } </pre> <p><b>Note: </b>If <a href="qml-qt-labs-controls-combobox.html">ComboBox</a> is assigned a data model that has multiple named roles, but <a href="qml-qt-labs-controls-combobox.html#textRole-prop">textRole</a> is not defined, <a href="qml-qt-labs-controls-combobox.html">ComboBox</a> is unable to visualize it and throws a <code>ReferenceError: modelData is not defined</code>.</p><p><b>Note: </b><i>Types in the Qt.labs module are not guaranteed to remain compatible in future versions.</i></p><p><b>See also </b><a href="qtlabscontrols-customize.html#customizing-combobox">Customizing ComboBox</a> and <a href="qtlabscontrols-input.html">Input Controls</a>.</p> <!-- @@@ComboBox --> <h2>Property Documentation</h2> <!-- $$$count --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="count-prop"> <td class="tblQmlPropNode"><p> <a name="count-prop"></a><span class="qmlreadonly">[read-only] </span><span class="name">count</span> : <span class="type">int</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the number of items in the combo box.</p> </div></div><!-- @@@count --> <br/> <!-- $$$currentIndex --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="currentIndex-prop"> <td class="tblQmlPropNode"><p> <a name="currentIndex-prop"></a><span class="name">currentIndex</span> : <span class="type">int</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the index of the current item in the combo box.</p> <p><b>See also </b><a href="qml-qt-labs-controls-combobox.html#activated-signal">activated()</a> and <a href="qml-qt-labs-controls-combobox.html#currentText-prop">currentText</a>.</p> </div></div><!-- @@@currentIndex --> <br/> <!-- $$$currentText --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="currentText-prop"> <td class="tblQmlPropNode"><p> <a name="currentText-prop"></a><span class="qmlreadonly">[read-only] </span><span class="name">currentText</span> : <span class="type">string</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the text of the current item in the combo box.</p> <p><b>See also </b><a href="qml-qt-labs-controls-combobox.html#currentIndex-prop">currentIndex</a>, <a href="qml-qt-labs-controls-combobox.html#displayText-prop">displayText</a>, and <a href="qml-qt-labs-controls-combobox.html#textRole-prop">textRole</a>.</p> </div></div><!-- @@@currentText --> <br/> <!-- $$$delegate --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="delegate-prop"> <td class="tblQmlPropNode"><p> <a name="delegate-prop"></a><span class="name">delegate</span> : <span class="type">Component</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds a delegate that presents an item in the combo box popup.</p> <p><b>See also </b><a href="qml-qt-labs-controls-itemdelegate.html">ItemDelegate</a> and <a href="qtlabscontrols-customize.html#customizing-combobox">Customizing ComboBox</a>.</p> </div></div><!-- @@@delegate --> <br/> <!-- $$$displayText --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="displayText-prop"> <td class="tblQmlPropNode"><p> <a name="displayText-prop"></a><span class="name">displayText</span> : <span class="type">string</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the text that is displayed on the combo box button.</p> <p>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.</p> <pre class="cpp"> ComboBox { currentIndex: <span class="number">1</span> displayText: <span class="string">"Size: "</span> <span class="operator">+</span> currentText model: <span class="operator">[</span><span class="string">"S"</span><span class="operator">,</span> <span class="string">"M"</span><span class="operator">,</span> <span class="string">"L"</span><span class="operator">]</span> } </pre> <p><b>See also </b><a href="qml-qt-labs-controls-combobox.html#currentText-prop">currentText</a> and <a href="qml-qt-labs-controls-combobox.html#textRole-prop">textRole</a>.</p> </div></div><!-- @@@displayText --> <br/> <!-- $$$highlightedIndex --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="highlightedIndex-prop"> <td class="tblQmlPropNode"><p> <a name="highlightedIndex-prop"></a><span class="qmlreadonly">[read-only] </span><span class="name">highlightedIndex</span> : <span class="type">int</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the index of the highlighted item in the combo box popup list.</p> <p><b>See also </b><a href="qml-qt-labs-controls-combobox.html#highlighted-signal">highlighted()</a> and <a href="qml-qt-labs-controls-combobox.html#currentIndex-prop">currentIndex</a>.</p> </div></div><!-- @@@highlightedIndex --> <br/> <!-- $$$model --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="model-prop"> <td class="tblQmlPropNode"><p> <a name="model-prop"></a><span class="name">model</span> : <span class="type"><a href="qml-qt-labs-controls-combobox.html#model-prop">model</a></span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the model providing data for the combo box.</p> <pre class="cpp"> ComboBox { textRole: <span class="string">"key"</span> model: ListModel { ListElement { key: <span class="string">"First"</span>; value: <span class="number">123</span> } ListElement { key: <span class="string">"Second"</span>; value: <span class="number">456</span> } ListElement { key: <span class="string">"Third"</span>; value: <span class="number">789</span> } } } </pre> <p><b>See also </b><a href="qml-qt-labs-controls-combobox.html#textRole-prop">textRole</a> and Data Models.</p> </div></div><!-- @@@model --> <br/> <!-- $$$popup --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="popup-prop"> <td class="tblQmlPropNode"><p> <a name="popup-prop"></a><span class="name">popup</span> : <span class="type"><a href="qml-qt-labs-controls-popup.html">Popup</a></span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the popup.</p> <p><b>See also </b><a href="qtlabscontrols-customize.html#customizing-combobox">Customizing ComboBox</a>.</p> </div></div><!-- @@@popup --> <br/> <!-- $$$pressed --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="pressed-prop"> <td class="tblQmlPropNode"><p> <a name="pressed-prop"></a><span class="name">pressed</span> : <span class="type">bool</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds whether the combo box button is pressed.</p> </div></div><!-- @@@pressed --> <br/> <!-- $$$textRole --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="textRole-prop"> <td class="tblQmlPropNode"><p> <a name="textRole-prop"></a><span class="name">textRole</span> : <span class="type">string</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the model role used for populating the combo box.</p> <p><b>See also </b><a href="qml-qt-labs-controls-combobox.html#model-prop">model</a>, <a href="qml-qt-labs-controls-combobox.html#currentText-prop">currentText</a>, and <a href="qml-qt-labs-controls-combobox.html#displayText-prop">displayText</a>.</p> </div></div><!-- @@@textRole --> <br/> <h2>Signal Documentation</h2> <!-- $$$activated --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="activated-signal"> <td class="tblQmlFuncNode"><p> <a name="activated-signal"></a><span class="type">void</span> <span class="name">activated</span>(<span class="type">int</span> <i>index</i>)</p></td></tr> </table></div> </div><div class="qmldoc"><p>This signal is emitted when the item at <i>index</i> is activated by the user.</p> <p><b>See also </b><a href="qml-qt-labs-controls-combobox.html#currentIndex-prop">currentIndex</a>.</p> </div></div><!-- @@@activated --> <br/> <!-- $$$highlighted --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="highlighted-signal"> <td class="tblQmlFuncNode"><p> <a name="highlighted-signal"></a><span class="type">void</span> <span class="name">highlighted</span>(<span class="type">int</span> <i>index</i>)</p></td></tr> </table></div> </div><div class="qmldoc"><p>This signal is emitted when the item at <i>index</i> in the popup list is highlighted by the user.</p> <p><b>See also </b><a href="qml-qt-labs-controls-combobox.html#highlightedIndex-prop">highlightedIndex</a>.</p> </div></div><!-- @@@highlighted --> <br/> <h2>Method Documentation</h2> <!-- $$$find --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="find-method"> <td class="tblQmlFuncNode"><p> <a name="find-method"></a><span class="type">int</span> <span class="name">find</span>(<span class="type">string</span> <i>text</i>, <i>flags</i> = Qt.MatchExactly)</p></td></tr> </table></div> </div><div class="qmldoc"><p>Returns the index of the specified <i>text</i>, or <code>-1</code> if no match is found.</p> <p>The way the search is performed is defined by the specified match <i>flags</i>. By default, combo box performs case sensitive exact matching (<code>Qt.MatchExactly</code>). All other match types are case-insensitive unless the <code>Qt.MatchCaseSensitive</code> flag is also specified.</p> <div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tbldscr">Description</th></tr> <tr><td class="topAlign"><code>Qt.MatchExactly</code></td><td class="topAlign">The search term matches exactly (default).</td></tr> <tr><td class="topAlign"><code>Qt.MatchRegExp</code></td><td class="topAlign">The search term matches as a regular expression.</td></tr> <tr><td class="topAlign"><code>Qt.MatchWildcard</code></td><td class="topAlign">The search term matches using wildcards.</td></tr> <tr><td class="topAlign"><code>Qt.MatchFixedString</code></td><td class="topAlign">The search term matches as a fixed string.</td></tr> <tr><td class="topAlign"><code>Qt.MatchStartsWith</code></td><td class="topAlign">The search term matches the start of the item.</td></tr> <tr><td class="topAlign"><code>Qt.MatchEndsWidth</code></td><td class="topAlign">The search term matches the end of the item.</td></tr> <tr><td class="topAlign"><code>Qt.MatchContains</code></td><td class="topAlign">The search term is contained in the item.</td></tr> <tr><td class="topAlign"><code>Qt.MatchCaseSensitive</code></td><td class="topAlign">The search is case sensitive.</td></tr> </table></div> <p><b>See also </b><a href="qml-qt-labs-controls-combobox.html#textRole-prop">textRole</a>.</p> </div></div><!-- @@@find --> <br/> <!-- $$$textAt --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="textAt-method"> <td class="tblQmlFuncNode"><p> <a name="textAt-method"></a><span class="type">string</span> <span class="name">textAt</span>(<span class="type">int</span> <i>index</i>)</p></td></tr> </table></div> </div><div class="qmldoc"><p>Returns the text for the specified <i>index</i>, or an empty string if the index is out of bounds.</p> <p><b>See also </b><a href="qml-qt-labs-controls-combobox.html#textRole-prop">textRole</a>.</p> </div></div><!-- @@@textAt --> <br/> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>