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

QDialog::open() messes up focusing widgets on MacOS

XMLWordPrintable

    • macOS
    • 223066d4319d611e724da69089c8f49d525a2566 (qt/qtbase/dev) 92d2d31e1a8a03ed56750b5c1c32b5cd22216b99 (qt/qtbase/6.2)

      When QDialog::open() is used, the focus is given always to the first widget in the dialog even though another widget was explicitly set to be focused.

      After many trials and errors, I found workaround: Setting setWindowModality(Qt::WindowModal) for the dialog solves the problem and focus is set properly. Anyway this is a bug to fixed.

      See snippet. Try it as it is and button b1 will be focused, which is wrong. Uncomment the line and button b2 will be focused, which is correct.

      #include <QApplication>
      #include <QDialog>
      #include <QPushButton>
      #include <QVBoxLayout>
      
      class Widget : public QDialog
      {
      public:
          Widget(QWidget *parent = nullptr) : QDialog(parent)
          {
              setLayout(new QVBoxLayout());
              auto b1 = new QPushButton("A");
              layout()->addWidget(b1);
              auto b2 = new QPushButton("B");
              layout()->addWidget(b2);
              b2->setFocus(); // Setting focus to b2 !!!
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          Widget w;
      
          // When this line is commented out, button b1 gets focus !!!
          //w.setWindowModality(Qt::WindowModality::WindowModal);
      
          w.open();
          return a.exec();
      }
      

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

            dorisverria Doris Verria
            vladimir.kraus Vladimir Kraus
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes