Fix QSplashscreen positioning on Android

Android does not use QPlatformWindow::initialGeometry(),
so the underlying assumption of 56e92dfdf2
was wrong. Try to explicitly find a screen and default to primary.

Fixes: QTBUG-73794
Change-Id: Iba3e70657a60babfcedf751335ca55cb971a4f99
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Friedemann Kleint 2019-02-14 11:45:13 +01:00
parent 93a78799c3
commit 655e8623af

View File

@ -289,8 +289,7 @@ void QSplashScreen::setPixmap(const QPixmap &pixmap)
// 1) If a QDesktopScreenWidget is found in the parent hierarchy, use that (see docs on // 1) If a QDesktopScreenWidget is found in the parent hierarchy, use that (see docs on
// QSplashScreen(QWidget *, QPixmap). // QSplashScreen(QWidget *, QPixmap).
// 2) If a widget with associated QWindow is found, use that // 2) If a widget with associated QWindow is found, use that
// 3) When nothing can be found, do not position the widget, allowing for // 3) When nothing can be found, try to center it over the cursor
// QPlatformWindow::initialGeometry() to center it over the cursor
static inline int screenNumberOf(const QDesktopScreenWidget *dsw) static inline int screenNumberOf(const QDesktopScreenWidget *dsw)
{ {
@ -307,7 +306,15 @@ const QScreen *QSplashScreenPrivate::screenFor(const QWidget *w)
if (QWindow *window = p->windowHandle()) if (QWindow *window = p->windowHandle())
return window->screen(); return window->screen();
} }
return nullptr; #if QT_CONFIG(cursor)
// Note: We could rely on QPlatformWindow::initialGeometry() to center it
// over the cursor, but not all platforms (namely Android) use that.
if (QGuiApplication::screens().size() > 1) {
if (auto screenAtCursor = QGuiApplication::screenAt(QCursor::pos()))
return screenAtCursor;
}
#endif // cursor
return QGuiApplication::primaryScreen();
} }
void QSplashScreenPrivate::setPixmap(const QPixmap &p, const QScreen *screen) void QSplashScreenPrivate::setPixmap(const QPixmap &p, const QScreen *screen)