Reputation: 35408
My application on startup creates a sort-of "Splash Screen" with quick access buttons to Open, New, etc... This splash window is placed in the middle of the screen, and the application main window is placed behind it.
Here is the code to do it:
void MainWindowButtonDialog::showMe()
{
setModal(false);
setWindowFlags(
#ifdef Q_WS_WIN
Qt::SplashScreen |
#endif
Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
QDesktopWidget *d = QApplication::desktop();
QRect t = d->availableGeometry(this);
move(mapToGlobal(this->geometry().topLeft()).x() + t.center().x() - width() / 2,
t.center().y()- height() / 2);
show();
raise();
}
However I have some problems when the application runs on a two monitor setup. What happens is the following: the Splash screen regardless where the application starts, is created always on the first screen. So if the Window manager decided to open the application on the second screen the splash screen will be far far away on the middle of the first screen... Which is pretty ugly :(
Any idea how can this be fixed?
Upvotes: 1
Views: 1730
Reputation: 27611
If you add the splash screen as a child to the MainWindow, it should have its initial coordinates set such that it displays right on top of its parent.
Upvotes: 1
Reputation: 601
Try calling availableGeometry() not with a widget as parameter, but with a screen number. Something like
int screen = d->primaryScreen();
QRect t = d->availableGeometry(screen);
Upvotes: 1