tdf#173219 tdf#130857 qt weld: Use QMessageBox API to add buttons

When adding buttons to a QMessageBox, use the QMessageBox API
(QMessageBox::addButton) instead of using the QDialogButtonBox
API of the button box inside of the message box.

While both should have the same effect in general, that is not
necessarily true in practice when a native platform implementation gets
used, like the one newly introduced for KDE Plasma in [1]

    commit e95889873fb03efbc1cea4d41b330f9243f5f626
    Author: Tobias Fella <fella@posteo.de>
    Date:   Tue Apr 28 15:02:17 2026 +0000

        Add QMessageBox backend for MessageDialog

        Make the Platform theme provide a native implementation of MessageDialog. For widgets apps, this effectively shouldn't change anything, since the implementation uses the same component; for QML apps using `MessageDialog`, the QMessageBox widget is now used as implementation instead of a qt-provided qml fallback, which is a significant visual improvement:
        [...]

QMessageDialogOptions::customButtons() used in the
KDEPlatformMessageDialogHelper (which subclasses
QPlatformMessageDialogHelper) implementation doesn't
return/take into account buttons directly added to the button
box, but takes into account those added using
QMessageBox::addButton.

Use the latter to add the buttons to avoid the problem
of message dialogs (like the "Save Document?" one)
missing buttons when using the qt6 or kf6 vcl plugin
with SAL_VCL_QT_USE_WELDED_WIDGETS=1 in a KDE Plasma
session new enough to make use of the native message dialog
introduced in the above plasma-integration commit.

(Issue seen e.g. with plasma-integration 6.7.4-1 on
Debian testing when the system Qt is used, but not
a self-compiled Qt dev, where the platform integration
wasn't used.)

[1] https://invent.kde.org/plasma/plasma-integration/-/commit/e95889873fb03efbc1cea4d41b330f9243f5f626

Change-Id: Ied541e76e119493be3288ea899e00d5fbd560ec2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/209456
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
(cherry picked from commit c4b307b8d2)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/209466
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-by: Dan Williams <dcbw@libreoffice.org>
Reviewed-by: Jonathan Clark <jonathan@libreoffice.org>
Tested-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn
2026-08-27 23:13:53 +02:00
parent 1485b4cd86
commit d27beae820
+8 -2
View File
@@ -921,11 +921,17 @@ void QtBuilder::setButtonProperties(QAbstractButton& rButton, stringmap& rProps,
if (QDialogButtonBox* pButtonBox = qobject_cast<QDialogButtonBox*>(pParentWidget))
{
pButtonBox->addButton(&rButton, QDialogButtonBox::NoRole);
// for message boxes, avoid implicit standard buttons in addition to those explicitly added
// and add button via QMessageBox API instead of via the button box
if (QMessageBox* pMessageBox = qobject_cast<QMessageBox*>(pParentWidget->window()))
{
pMessageBox->setStandardButtons(QMessageBox::NoButton);
pMessageBox->addButton(&rButton, QMessageBox::ButtonRole::NoRole);
}
else
{
pButtonBox->addButton(&rButton, QDialogButtonBox::NoRole);
}
}
}