Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-75338

Editable ComboBox: currentIndex is not set to -1 and currentText not cleared after confirming non-existent value

    XMLWordPrintable

Details

    • 616c430d2b7f36e70987df7b2dc97e71f0e8b589 (qt/qtquickcontrols2/5.12)

    Description

      When inputting and confirming (Return or Enter) a string which is not contained in the model of an editable ComboBox, the currentIndex and currentText will stay unchanged (Banana is the first item in the model and thus selected by default).

      editText: Test
      currentText: Banana
      currentIndex: 0
      

      What should happen is that the currentIndex should be set to -1 and the currentText should probably be set to the confirmed string (look at the documentation snippet below).
      To get the proper behavior the user has to confirm the input a second time.

      editText: Test
      currentText: 
      currentIndex: -1
      

      Even though the currentIndex is set correctly after the second confirmation, the currentText is empty , but this might be intended.

      The ComboBox documentation contains the following statement

      This signal is emitted when the Return or Enter key is pressed on an editable combo box. If the confirmed string is not currently in the model, the currentIndex will be set to -1 and the currentText will be updated accordingly.

      ComboBox {
          editable: true
          model: ["Banana", "Apple", "Coconut", "Kiwi", "Mango #5", "Pomelo"]
          anchors.top: parent.top
          anchors.topMargin: 10
          anchors.horizontalCenter: parent.horizontalCenter
          onEditTextChanged: console.log("onEditTextChanged: " + editText)
          onAccepted: console.log("onAccepted.\neditText: " + editText +"\ncurrentText: " + currentText + "\ncurrentIndex: " + currentIndex)
      }
      

      The following snippet shows the console output of the ComboBox code above. The user entered Test and hit enter twice.

      qml: onEditTextChanged: Banana
      qml: onEditTextChanged: T
      qml: onEditTextChanged: Te
      qml: onEditTextChanged: Tes
      qml: onEditTextChanged: Test
      qml: onAccepted.
      editText: Test
      currentText: Banana
      currentIndex: 0
      
      qml: onAccepted.
      editText: Test
      currentText: 
      currentIndex: -1
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            henning Henning Gründl
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes