From 8753bb3045d020bcae33eed67a2770a4709ac7b8 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 9 Nov 2023 12:27:37 +0200 Subject: [PATCH] Cocoa MessageBox: don't use native message box if detailed text is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As per the documentation: A message box displays a primary text to alert the user to a situation, an informative text to further explain the situation, and an optional detailed text to provide even more data if the user requests it. The AppKit NSAlert doesn't provide such a "detailed" section, and our code just added this "even more data" detailed text to the primary text. This breaks the UI when the detailed text is very long, perhaps a complete log output with dozens or even hundreds of lines of text. Since NSAlert doesn't provide a "details" space, fall-back to the non- native message box if detailed text is provided. [ChangeLog][QtWidgets][QMessageBox] On Apple platforms, the native message box is no longer used when detailed text is set. Pick-to: 6.6 6.5 Fixes: QTBUG-118992 Change-Id: I6f4764ceb8f8e57d641c0b0660223a9c26f5bd26 Reviewed-by: Tor Arne Vestbø Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoamessagedialog.mm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm index b09f6bf54e6..82a4c90c236 100644 --- a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm +++ b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm @@ -91,6 +91,12 @@ bool QCocoaMessageDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality w if (!options()) return false; + // NSAlert doesn't have a section for detailed text + if (!options()->detailedText().isEmpty()) { + qCWarning(lcQpaDialogs, "Message box contains detailed text"); + return false; + } + if (Qt::mightBeRichText(options()->text()) || Qt::mightBeRichText(options()->informativeText())) { // Let's fallback to non-native message box, @@ -103,10 +109,7 @@ bool QCocoaMessageDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality w m_alert = [NSAlert new]; m_alert.window.title = options()->windowTitle().toNSString(); - QString text = toPlainText(options()->text()); - QString details = toPlainText(options()->detailedText()); - if (!details.isEmpty()) - text += u"\n\n"_s + details; + const QString text = toPlainText(options()->text()); m_alert.messageText = text.toNSString(); m_alert.informativeText = toPlainText(options()->informativeText()).toNSString();