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

Adding widget in empty layout in QDialog sometimes moves dialog to (0,0)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12, 5.15, 6.2, 6.4, 6.6, 6.8
    • None
    • Linux/Wayland, Linux/X11, macOS, Windows

    Description

      Hello,

      I've had this bug happen for years and years - I'm sure it was there in like Qt 5.6-ish already.

      Basically, in some circumstances, and with very random probability of occuring (e.g. sometimes it won't happen for 10 subsequent launches, then it will keep happening), the dialog will show up at the top-left of my screen instead of the center.

      • If setWidget is called synchronously I cannot reproduce the issue
      • Parent of the dialog does not matter
      • QGridLayout instead of QH/VBoxLayout gives the same result
      • Just having a single QPushButton without a QMainWindow gives the same result
      • show() instead of exec() also has the bug

      Here is a standalone repro: 

      #include <QApplication>
      #include <QDialog>
      #include <QFormLayout>
      #include <QHBoxLayout>
      #include <QLabel>
      #include <QMainWindow>
      #include <QPushButton>
      #include <QTimer>
      
      class MyDialog : public QDialog
      {
      public:
          explicit MyDialog(QWidget *parent)
              : QDialog{parent}
          {
              m_layout = new QFormLayout;
              setLayout(m_layout);
      
              m_subLayout = new QHBoxLayout;
              m_layout->addRow(m_subLayout);
      
              QTimer::singleShot(0, [this] { setWidget(); });
          }
      
          void setWidget()
          {
              m_label = new QLabel("hello");
              m_subLayout->addWidget(m_label);
          }
      
          QFormLayout *m_layout{};
          QHBoxLayout *m_subLayout{};
          QLabel *m_label{};
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv); 
          MyDialog d{nullptr}; 
          d.exec();
          return a.exec();
      }

      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
            jcelerier Jean-Michaël Celerier
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes