[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)
{
QMainWindow::showEvent(event);if(event->spontaneous() || isWindowLoaded)
return;SomeCreatedDilalog->exec();
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)
{
//qDebug()<<ev->type();
bool isHandled = QMainWindow::event(ev);
if(isHandled)
{
// Emit signal when window activated in first.
if(ev->type() == QEvent::WindowActivate && !isWindowLoaded)
{
qDebug()<<isWindowLoaded;
qDebug()<<ev->type();
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;
mainWindow.show();Dialog dialog;
dialog.exec();...
@ -
-
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;
mw.show();
Dialog dlg = new Dialog(&mw); //It is modal for his parrent
dlg->exec();
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)
{
QMainWindow::showEvent(event);
QTimer::singleShot(0, this, SLOT(dialogExec));
}
@Then in dialogExec slot, call yourDialog->exec()
-
Greate. This solution more suitable for me.
Thanks to all.