vcl/qt5/QtInstance.cxx |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

New commits:
commit 9e40fc8c9458b937200ea56c96b89113c74b67f5
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Feb 14 10:54:59 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Feb 15 08:08:05 2024 +0100

    tdf#130857 qt weld: Set msg dialog parent
    
    If a parent is passed to `QtInstance::CreateMessageDialog`,
    also set a parent for the `QMessageBox` that gets created
    there:
    
    If the passed parent is a native Qt one, use that one.
    Otherwise, fall back to using the current active top-level
    window, which is what usually makes most sense and is better
    than having no parent at all.
    
    With this change in place, the message dialog shown
    when doing
    
    1) start Writer
    2) "File" -> "Properties" -> "Security" -> "Protect"
    3) type 2 different passwords and confirm
    
    is now modal and centered on top of the "Enter Password"
    dialog on KDE Plasma Wayland when using the qt6 VCL plugin,
    while it used to open at the top left of the screen and was
    non-modal before.
    
    The new behavior is in line with how it behaves for the
    SAL_VCL_QT_NO_WELDED_WIDGETS=1 case.
    
    Change-Id: Ibe95c2f0407edeba0fd9f76744bc087be7df6437
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163362
    Tested-by: Jenkins
    Reviewed-by: Omkar Acharekar  <omkarachareka...@gmail.com>
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtInstance.cxx b/vcl/qt5/QtInstance.cxx
index f2f8caa6b86a..6b3bd0cc301a 100644
--- a/vcl/qt5/QtInstance.cxx
+++ b/vcl/qt5/QtInstance.cxx
@@ -792,7 +792,21 @@ weld::MessageDialog* 
QtInstance::CreateMessageDialog(weld::Widget* pParent,
     }
     else
     {
-        QMessageBox* pMessageBox = new QMessageBox();
+        QWidget* pQtParent = nullptr;
+        if (pParent)
+        {
+            if (QtInstanceWidget* pQtInstanceWidget = 
dynamic_cast<QtInstanceWidget*>(pParent))
+            {
+                pQtParent = pQtInstanceWidget->getQWidget();
+            }
+            else
+            {
+                // the parent is not welded/not a native Qt widget; fall back 
to currently active window
+                pQtParent = QApplication::activeWindow();
+            }
+        }
+
+        QMessageBox* pMessageBox = new QMessageBox(pQtParent);
         pMessageBox->setText(toQString(rPrimaryMessage));
         pMessageBox->setIcon(vclMessageTypeToQtIcon(eMessageType));
         pMessageBox->setWindowTitle(vclMessageTypeToQtTitle(eMessageType));

Reply via email to