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

New version of QWidget::setFocusProxy breaks keyboard focus

    XMLWordPrintable

Details

    • 23b998fa454ca021aa595f66d2e1964da4a119a4 (qt/qtbase/dev) 79008da82d9b5bcb99df88ff8b9dc5e130675e53 (qt/qtbase/5.15)
    • Bug Fixing Week Q2/2020

    Description

      #include <QApplication>
      #include <QLayout>
      #include <QLineEdit>
      #include <QPushButton>
      
      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);
      
          QWidget window;
          auto layout = new QHBoxLayout(&window);
      
          auto button = new QPushButton(&window);
          layout->addWidget(button);
      
          auto edit = new QLineEdit(&window);
          layout->addWidget(edit);
      
          QObject::connect(button, &QPushButton::clicked,
                           [button, edit] { button->setFocusProxy(edit); });
      
          window.show();
      
          return QApplication::exec();
      }

      Start this application and press the space bar to make the line edit the focus proxy of the button.

      This is now supposed to move the keyboard focus to the line edit, but it happens only partially: you can't enter any text, pressing the space bar pushes the button, and yet the menu key opens the line edit's context menu. Switching to the other window and back fixes that.

      The missing part of the new setFocusProxy seems to be updating focus_child of the parent widgets — that's what happens in QWidget::setFocus and QWidget::clearFocus together with QApplicationPrivate::setFocusWidget.

      Attachments

        Issue Links

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

          Activity

            People

              vhilshei Volker Hilsheimer
              a.khlyustov a.khlyustov
              Votes:
              4 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes