How to keep a QWidget (or QDialog) centered to its parent widget?

c++, qt

Solution

I solved it myself and just to answer my own question if someone will find it helpful.

Keep it in the center:

void MyMainWindow::moveEvent(QMoveEvent* event)
{
    const QPoint global = this->mapToGlobal(rect().center());
    waitDialog->move(global.x() - waitDialog->width() / 2, global.y() - waitDialog->height() / 2);
}

... where `waitDialog` is an instance of my "Wait..." indicator. This needs to override the `moveEvent` method of the parent (here `MyMainWindow`).

Problem

I want to keep a QWidget (or QDialog) centered to its parent widget. Is it really required to connect to signals of the parent widget or is there an easier way (something to set)?

Original source