vcl/inc/qt5/QtMenu.hxx |    1 -
 vcl/qt5/QtMenu.cxx     |    8 +++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

New commits:
commit 664ea7545a62e1329eb1761caea25b7f31cafa7a
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Wed Apr 6 16:42:24 2022 +0200
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Tue Apr 12 20:18:41 2022 +0200

    tdf#148491 Qt reconnect the QMenuBar close button
    
    When the QMenuBar of a QMainWindow is replaced, an existing
    corner widget is preserved / transferred, but its connections
    are still severed; a bit unexpected...
    
    The documentation for QMenuBar::setCornerWidget is not really
    clear what is happening, but the code has this nice comment:
    "// Reparent corner widgets before we delete the old menu".
    At least there is no need to explicitly delete the button.
    
    Still we must reconnect an existing button on each SetFrame.
    
    Regression from commit 9c4ef8ce3183e27ca174475cf4a8d15cc0368f60
    ("tdf#145954 Qt unshare QMenubar usage").
    
    This includes commit 4a537cf77affc4f1f2e2e5be9ff0b1ff11724509
    ("Qt drop unused QtMenu::mpCloseButton").
    
    Change-Id: I13c31734e665b78231a08cd76ca6305122e08879
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132836
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    (cherry picked from commit f751417b77e6573a0c639778e76ec943449f4573)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132894
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>

diff --git a/vcl/inc/qt5/QtMenu.hxx b/vcl/inc/qt5/QtMenu.hxx
index f39be7e8d506..11f3f00c5aa6 100644
--- a/vcl/inc/qt5/QtMenu.hxx
+++ b/vcl/inc/qt5/QtMenu.hxx
@@ -49,7 +49,6 @@ private:
     std::unique_ptr<QMenu> mpOwnedQMenu;
     // pointer to QMenu owned by the corresponding QtMenuItem or self (-> 
mpOwnedQMenu)
     QMenu* mpQMenu;
-    QPushButton* mpCloseButton;
 
     void DoFullMenuUpdate(Menu* pMenuBar);
     static void NativeItemText(OUString& rItemText);
diff --git a/vcl/qt5/QtMenu.cxx b/vcl/qt5/QtMenu.cxx
index 44873ce3384d..9400f5e129bf 100644
--- a/vcl/qt5/QtMenu.cxx
+++ b/vcl/qt5/QtMenu.cxx
@@ -40,7 +40,6 @@ QtMenu::QtMenu(bool bMenuBar)
     , mbMenuBar(bMenuBar)
     , mpQMenuBar(nullptr)
     , mpQMenu(nullptr)
-    , mpCloseButton(nullptr)
 {
 }
 
@@ -431,7 +430,9 @@ void QtMenu::SetFrame(const SalFrame* pFrame)
     mpQMenuBar = new QMenuBar();
     pMainWindow->setMenuBar(mpQMenuBar);
 
-    mpCloseButton = nullptr;
+    QPushButton* pButton = 
static_cast<QPushButton*>(mpQMenuBar->cornerWidget(Qt::TopRightCorner));
+    if (pButton)
+        connect(pButton, &QPushButton::clicked, this, 
&QtMenu::slotCloseDocument);
     mpQMenu = nullptr;
 
     DoFullMenuUpdate(mpVCLMenu);
@@ -650,6 +651,8 @@ void QtMenu::ShowCloseButton(bool bShow)
         return;
 
     QPushButton* pButton = 
static_cast<QPushButton*>(mpQMenuBar->cornerWidget(Qt::TopRightCorner));
+    if (!pButton && !bShow)
+        return;
     if (!pButton)
     {
         QIcon aIcon;
@@ -665,7 +668,6 @@ void QtMenu::ShowCloseButton(bool bShow)
         pButton->setToolTip(toQString(VclResId(SV_HELPTEXT_CLOSEDOCUMENT)));
         mpQMenuBar->setCornerWidget(pButton, Qt::TopRightCorner);
         connect(pButton, &QPushButton::clicked, this, 
&QtMenu::slotCloseDocument);
-        mpCloseButton = pButton;
     }
 
     if (bShow)

Reply via email to