QMessageBox: read geometry from the screen the message box belongs to

The current implementation found a QScreen by using the
position of the mouse in a call to QGuiApplication::screenAt().
From the documentation, this function is allowed to return
nullptr if the position is outside the screen.

From the stack track in the bug report, it seems very likely
that the mentioned call returns nullptr. This is strengthen
by the fact that the crash happens for messageboxes that are
maximized, so that you need to click on the upper corner of the
screen to close it. And then only when HiDPI scaling is in use
at the same time.

This patch will change the code to just use the screen that the
widget is on instead. If no screen can be resolved, the call will
default to primary screen.

Fixes: QTBUG-96639
Pick-to: 6.2
Change-Id: I31f0301318b358be9619caa31cc831b9598d5f90
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Richard Moe Gustavsen 2021-09-21 15:51:16 +02:00
parent 7c26d7f482
commit e9cef8e7fa

View File

@ -363,7 +363,7 @@ void QMessageBoxPrivate::updateSize()
if (!q->isVisible())
return;
const QSize screenSize = QGuiApplication::screenAt(QCursor::pos())->availableGeometry().size();
const QSize screenSize = q->screen()->availableGeometry().size();
int hardLimit = qMin(screenSize.width() - 480, 1000); // can never get bigger than this
// on small screens allows the messagebox be the same size as the screen
if (screenSize.width() <= 1024)