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

Using setFocusProxy can result in multiple buttons having focus

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.12.6, 5.14.0
    • Fix Version/s: None
    • Component/s: GUI: Look'n'Feel
    • Labels:
      None
    • Environment:
      OS X 10.13, OS X 10.14, OS X 10.15
    • Platform/s:
      macOS

      Description

      Create 2 line edits and buttons. Set each line edit as focus proxy for a button.

      Minimal sample code:

      #include <QApplication>
      #include <QHBoxLayout>
      #include <QLineEdit>
      #include <QPushButton>
      #include <QMainWindow>
      #include <QVBoxLayout>
      
      class TestWindow : public QMainWindow
      {
      public:
          TestWindow(QWidget *parent = nullptr) : QMainWindow(parent)
          {
              QLineEdit* le1 = new QLineEdit;
              QLineEdit* le2 = new QLineEdit;
      
              QPushButton* pb1 = new QPushButton("One");
              QPushButton* pb2 = new QPushButton("Two");
      
              pb1->setFocusProxy( le1 );
              pb2->setFocusProxy( le2 );
      
              QHBoxLayout* l1 = new QHBoxLayout;
              l1->addWidget(le1);
              l1->addWidget(pb1);
      
              QHBoxLayout* l2 = new QHBoxLayout;
              l2->addWidget(le2);
              l2->addWidget(pb2);
      
              QVBoxLayout* l3 = new QVBoxLayout;
              l3->addLayout(l1);
              l3->addLayout(l2);
      
              QWidget* w = new QWidget;
              w->setLayout(l3);
              setCentralWidget(w);
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          TestWindow w;
          w.show();
          return a.exec();
      }
      

      Steps to reproduce:

      • Launch the application
      • (Button "One" has a blue focus rectangle around it)
      • Click on the second line edit
      • Click on the second button
      • (Button "One" and "Two" have a blue focus rectangle around it, only 1 button should have focus at any given time)

      See attached Capture.png for an example of the wrong focus state on both buttons.

        Attachments

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

          Activity

            People

            Assignee:
            qt.team.quick.subscriptions Qt Quick and Widgets Team
            Reporter:
            fdca_enfocus fdca_enfocus
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes