vcl/inc/qt5/QtInstanceMenuButton.hxx |    3 +++
 vcl/qt5/QtInstanceMenuButton.cxx     |   13 +++++++++++++
 2 files changed, 16 insertions(+)

New commits:
commit 2ef30328ab45e9d64a7bbce87b04865c85c44b62
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Jan 14 17:30:48 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Jan 15 13:35:01 2025 +0100

    tdf#130857 qt weld: Signal MenuButton menu item selection
    
    Change-Id: I389993794db520778093845458daf0c89dec21b6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180252
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/qt5/QtInstanceMenuButton.hxx 
b/vcl/inc/qt5/QtInstanceMenuButton.hxx
index 398488076d30..5e472b24d183 100644
--- a/vcl/inc/qt5/QtInstanceMenuButton.hxx
+++ b/vcl/inc/qt5/QtInstanceMenuButton.hxx
@@ -40,6 +40,9 @@ public:
 private:
     QMenu& getMenu() const;
     QAction* getAction(const OUString& rIdent) const;
+
+private Q_SLOTS:
+    void handleMenuItemTriggered(QAction* pAction);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt5/QtInstanceMenuButton.cxx b/vcl/qt5/QtInstanceMenuButton.cxx
index 1d0a19ee0a18..f6432abdc77d 100644
--- a/vcl/qt5/QtInstanceMenuButton.cxx
+++ b/vcl/qt5/QtInstanceMenuButton.cxx
@@ -21,8 +21,11 @@ QtInstanceMenuButton::QtInstanceMenuButton(QToolButton* 
pButton)
     , m_pToolButton(pButton)
 {
     assert(m_pToolButton);
-
     m_pToolButton->setPopupMode(QToolButton::InstantPopup);
+
+    assert(m_pToolButton->menu());
+    connect(m_pToolButton->menu(), &QMenu::triggered, this,
+            &QtInstanceMenuButton::handleMenuItemTriggered);
 }
 
 void QtInstanceMenuButton::insert_item(int nPos, const OUString& rId, const 
OUString& rStr,
@@ -144,4 +147,12 @@ QAction* QtInstanceMenuButton::getAction(const OUString& 
rIdent) const
     return nullptr;
 }
 
+void QtInstanceMenuButton::handleMenuItemTriggered(QAction* pAction)
+{
+    SolarMutexGuard g;
+
+    assert(pAction);
+    signal_selected(toOUString(pAction->objectName()));
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
commit 1506b6a3136269d54aa9eb8c99c4335170632f3b
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Jan 14 17:06:02 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Jan 15 13:34:47 2025 +0100

    tdf#130857 qt weld: Open menu button's menu instantly
    
    Set the QToolButton's popup mode to QToolButton::InstantPopup [1]
    
    > The menu is displayed, without delay, when the tool button
    > is pressed. In this mode, the button's own action is not triggered.
    
    Otherwise, the default of QToolButton::DelayedPopup is used
    and the menu only opens when clicking the button for a longer
    time, which is unintuitive for menu buttons:
    
    > After pressing and holding the tool button down for a certain amount of
    > time (the timeout is style dependent, see 
QStyle::SH_ToolButton_PopupDelay),
    > the menu is displayed. A typical application example is the "back" button 
in
    > some web browsers's tool bars. If the user clicks it, the browser simply 
browses
    > back to the previous page. If the user presses and holds the button down 
for a
    > while, the tool button shows a menu containing the current history list
    
    [1] https://doc.qt.io/qt-6/qtoolbutton.html#ToolButtonPopupMode-enum
    
    Change-Id: Ie4be457ec801cddd3eee02a7b8800b1400564216
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180251
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtInstanceMenuButton.cxx b/vcl/qt5/QtInstanceMenuButton.cxx
index 45191ef937f9..1d0a19ee0a18 100644
--- a/vcl/qt5/QtInstanceMenuButton.cxx
+++ b/vcl/qt5/QtInstanceMenuButton.cxx
@@ -21,6 +21,8 @@ QtInstanceMenuButton::QtInstanceMenuButton(QToolButton* 
pButton)
     , m_pToolButton(pButton)
 {
     assert(m_pToolButton);
+
+    m_pToolButton->setPopupMode(QToolButton::InstantPopup);
 }
 
 void QtInstanceMenuButton::insert_item(int nPos, const OUString& rId, const 
OUString& rStr,

Reply via email to