Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

qdialog show in different pos when it has different parent #72

@lzy-zj

Description

@lzy-zj

for example:

    QPushButton *btn = new QPushButton("p is gw", this);
    btn->move(200, 200);
    // this is GoodWindow
    connect(btn, &QPushButton::clicked, this, [=]() {
        QDialog d(this);
        d.setWindowTitle("p is gw");
        d.resize(400, 300);
        d.exec();
    });

    QPushButton *btn2 = new QPushButton("p is btn", this);
    btn2->move(200, 300);

    connect(btn2, &QPushButton::clicked, this, [=]() {
        QDialog d(btn);
        d.setWindowTitle("p is btn");
        d.resize(400, 300);
        d.exec();
    });

Image

Image

QRect QGoodWindow::geometry() const
{
#ifdef Q_OS_WIN
    RECT client_rect;
    GetClientRect(m_hwnd, &client_rect);

    int w = qFloor((client_rect.right - client_rect.left) / m_pixel_ratio);
    int h = qFloor((client_rect.bottom - client_rect.top) / m_pixel_ratio);

    QRect rect = QRect(x(), y(), w, h);

    qDebug() << "----------" << rect << QMainWindow::geometry();
    // ---------- QRect(931,516 593x470) QRect(0,0 593x470)

    return rect;
#else
    return QMainWindow::geometry();
#endif
}

And i find QMainWindow::geometry() always return (0, 0, x, x),when i use button as parent, qt may use QMainWindow::geometry(). Is there any way i do not have to get QGoodWindow::geometry()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions