Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.12, 5.15, 6.2, 6.4, 6.6, 6.8
-
None
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(); }