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

Strange behavior of return press when edit text is selected in QComboBox

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.7.3
    • None
    • Linux/X11

    Description

      Consider the following example:

      #include <QApplication> 
      #include <QComboBox> 
      #include <QLineEdit> 
      
      int main(int argc, char **argv) 
      { 
         QApplication app(argc, argv); 
      
         QComboBox cb; 
         cb.setFixedWidth(200); 
         cb.setEditable(true); 
         cb.addItem(QStringLiteral("Single Entry")); 
         cb.setEditText(QStringLiteral("Second Entry")); 
         cb.lineEdit()->selectAll(); 
         QObject::connect(cb.lineEdit(), &QLineEdit::returnPressed, &app, [&cb]() { qWarning("->%s", qPrintable(cb.currentText())); }); 
         cb.show(); 
      
         return app.exec(); 
      }

      Here, a QComboBox is created with an initial single entry. Then the edit text is set to something different and selected.

      Observed: On hitting Return you see the  initial single entry printed out on the console and the combobox shows this entry.

      Expected: On hitting Return you see the set edit text printed out on the console and the text in the combobox does not change (and perhaps the selection should stay as in a normal QLineEdit).

      Fun fact: If you do not select the text, the combobox behaves as expected.

      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
            mlangen Marc Langenbach
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes