Nominate our 2022 Qt Champions!

[SOLVED]How do I know that the window is fully displayed on the screen

  • I need do some actions when my main window if fully painted on screen.
    For this i tryed use showEvent:
    @void MyMainWindow::showEvent(QShowEvent *event)

    if(event->spontaneous() || isWindowLoaded)


    isWindowLoaded = true;
    But when i am use this code SomeCreatedDialog is shown on screen before MainWindow.
    This dialog is modal, so i must close it. And only after this MainWindow will displaed.

    And my question: How i can display MainWindow on screen and only after this display modal dilaog?

  • Okay... I think i can do what i want with handaling WindowActivate event:
    @bool MainWindow::event(QEvent* ev)
    bool isHandled = QMainWindow::event(ev);
    // Emit signal when window activated in first.
    if(ev->type() == QEvent::WindowActivate && !isWindowLoaded)
    isWindowLoaded = true;
    emit MainWindowShown();
    return isHandled;

    Maybe someone know best solution?

  • In MyMainWindow::showEvent fire a single shot timer connected to some slot say execDialog. In this slot call "SomeCreatedDilalog->exec()"

  • Well, what about ... ?
    MainWindow mainWindow;;

    Dialog dialog;


  • @Lukas, obviously your solution is the most viable, but from what I understand, @Elijah has called MainWindow :: show(). Maybe I don't understand exactly :-)

  • Lukas, cincirin Yes this silution is most viable - but does not work for me.
    How i say before i need modal dialog, so i must show this dialog with exec() method (not show()).
    And if i have this main function:
    @int main(int argc, char argv[])
    QApplication a(argc, argv);
    MainWindow mw;;
    dlg = new Dialog(&mw); //It is modal for his parrent
    return a.
    This solution perfect.

    But i need call modal dialog in his parent class. And immediately after show parent.
    I need it for encapsulation.
    Okay, i can solve my problem with your solution but i think it is bad for my encapsulation.

  • Ok, then the solution with the single shot timer does not work ?
    MainWindow::::showEvent(QShowEvent *event)
    QTimer::singleShot(0, this, SLOT(dialogExec));

    Then in dialogExec slot, call yourDialog->exec()

  • Greate. This solution more suitable for me.
    Thanks to all.

Log in to reply