diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2019-05-02 16:50:31 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2019-09-06 09:19:15 +0200 |
commit | 616c430d2b7f36e70987df7b2dc97e71f0e8b589 (patch) | |
tree | 8dae20965ec6edf057faa547069715205db55102 /src/quicktemplates2 | |
parent | 1e99cb6e809ff0c8647c5017c11ead68ae1a591d (diff) |
ComboBox: document the behavior surrounding the accepted() signal
Change-Id: I65be8e54ded284d2f80b5a1f301b75223bd81bb3
Fixes: QTBUG-75338
Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquickcombobox.cpp | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp index 78ec7ef8..372b7905 100644 --- a/src/quicktemplates2/qquickcombobox.cpp +++ b/src/quicktemplates2/qquickcombobox.cpp @@ -90,21 +90,7 @@ QT_BEGIN_NAMESPACE The following example demonstrates appending content to an editable combo box by reacting to the \l accepted signal. - \code - ComboBox { - editable: true - model: ListModel { - id: model - ListElement { text: "Banana" } - ListElement { text: "Apple" } - ListElement { text: "Coconut" } - } - onAccepted: { - if (find(editText) === -1) - model.append({text: editText}) - } - } - \endcode + \snippet qtquickcontrols2-combobox-accepted.qml combobox \section1 ComboBox Model Roles @@ -167,9 +153,22 @@ QT_BEGIN_NAMESPACE \qmlsignal void QtQuick.Controls::ComboBox::accepted() This signal is emitted when the \uicontrol Return or \uicontrol Enter key is pressed - on an \l editable combo box. If the confirmed string is not currently in the model, - the \l currentIndex will be set to \c -1 and the \l currentText will be updated - accordingly. + on an \l editable combo box. + + You can handle this signal in order to add the newly entered + item to the model, for example: + + \snippet qtquickcontrols2-combobox-accepted.qml combobox + + Before the signal is emitted, a check is done to see if the string + exists in the model. If it does, \l currentIndex will be set to its index, + and \l currentText to the string itself. + + After the signal has been emitted, and if the first check failed (that is, + the item did not exist), another check will be done to see if the item was + added by the signal handler. If it was, the \l currentIndex and + \l currentText are updated accordingly. Otherwise, they will be set to + \c -1 and \c "", respectively. \note If there is a \l validator set on the combo box, the signal will only be emitted if the input is in an acceptable state. |