From 1e817f3b8b921b81a6b8011b898c5e35035574c4 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Tue, 30 Dec 2025 10:28:57 +0100 Subject: Install middle click event handler on KXmlGui Toolbar menu For ease of access, KXmlGui adds actions in a delayed/split toolbar button to its own context menu. We have no access to this menu, so we cannot install our middle-click event handler for the back/forward action menus. To address this, we detect the action showing for the first time and install an event filter on the associated object if we think it's the menu. --- src/middleclickactioneventfilter.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/middleclickactioneventfilter.cpp') diff --git a/src/middleclickactioneventfilter.cpp b/src/middleclickactioneventfilter.cpp index 7f98e727e..2d943475a 100644 --- a/src/middleclickactioneventfilter.cpp +++ b/src/middleclickactioneventfilter.cpp @@ -7,6 +7,7 @@ #include "middleclickactioneventfilter.h" #include +#include #include #include #include @@ -55,6 +56,23 @@ bool MiddleClickActionEventFilter::eventFilter(QObject *watched, QEvent *event) } } } + + } else if (event->type() == QEvent::ActionChanged) { + // KXmlGui adds delayed popup menu's actions to its own context menu. + // In order for middle click to work, we need to somehow detect when the action is added + // on this menu and install the event filter on it. + // Visibility of the action changes when the menu shows in the menu for the first time, + // so we'll receive an ActionChanged event and use that. + auto *actionEvent = static_cast(event); + + const auto items = actionEvent->action()->associatedObjects(); + for (auto *item : items) { + if (auto *menu = qobject_cast(item)) { + if (menu != actionEvent->action()->parent()) { // Parent is the regular menu. + menu->installEventFilter(this); + } + } + } } return QObject::eventFilter(watched, event); -- cgit v1.3