From e9cef8e7fa1c1cf4956cd25ccc5504f2e7790e4e Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 21 Sep 2021 15:51:16 +0200 Subject: [PATCH] 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 --- src/widgets/dialogs/qmessagebox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index a3093f82c21..a6a4d588d3d 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -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)