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

ComboBox does not select currently suggested item when pressing tab

    XMLWordPrintable

Details

    • cb1c3528078659c297fb12ea6914978cec1d2614 (qt/qtquickcontrols2/5.14)

    Description

      When writing partial name of an entry, ComboBox suggests something. When user pressed tab or unfocuses the control, the suggested text remains, but currentIndex and currentText are both still the same as they were before typing something.

      It would seem logical that it selects the item it is suggesting by itself when pressing tab or focusing some other item. Or else it should revert back to the current item and clear the text.

      Example showing the expected behaviour using widgets:

      #include <QtWidgets>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QMainWindow mainWindow;
      
          QWidget *widget = new QWidget;
      
          QHBoxLayout *hBoxLayout = new QHBoxLayout(widget);
      
          QComboBox *comboBox = new QComboBox(widget);
          comboBox->setEditable(true);
      
          const QVector<QString> contents = { "Apple", "Banana", "Coconut" };
          auto *model = new QStandardItemModel(contents.size(), 1);
          for (int row = 0; row < contents.size(); ++row) {
              const auto &modelData = contents.at(row);
              auto *item = new QStandardItem(modelData);
              model->setItem(row, 0, item);
          }
          comboBox->setModel(model);
          QObject::connect(comboBox, qOverload<int>(&QComboBox::currentIndexChanged), [=]() {
              qDebug() << "currentIndex:" << comboBox->currentIndex();
          });
      
          hBoxLayout->addWidget(comboBox);
      
          auto button = new QPushButton(widget);
          hBoxLayout->addWidget(button);
      
          mainWindow.setCentralWidget(widget);
          mainWindow.centralWidget()->setLayout(hBoxLayout);
      
          mainWindow.resize(400, 400);
          mainWindow.show();
      
          return app.exec();
      }
      

      Attachments

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

        Activity

          People

            mitch_curtis Mitch Curtis
            poikelin Joni Poikelin
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes