diff options
| author | Kai Uwe Broulik <[email protected]> | 2025-12-30 10:28:57 +0100 |
|---|---|---|
| committer | Kai Uwe Broulik <[email protected]> | 2026-01-08 15:57:11 +0000 |
| commit | 1e817f3b8b921b81a6b8011b898c5e35035574c4 (patch) | |
| tree | 0cd7451fde439b5d67c47a12e677ca8094ed98f7 | |
| parent | 5b6dfad767522060596ba2a76044e14ca99db57b (diff) | |
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.
| -rw-r--r-- | src/middleclickactioneventfilter.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
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 <QAction> +#include <QActionEvent> #include <QEvent> #include <QMenu> #include <QMouseEvent> @@ -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<QActionEvent *>(event); + + const auto items = actionEvent->action()->associatedObjects(); + for (auto *item : items) { + if (auto *menu = qobject_cast<QMenu *>(item)) { + if (menu != actionEvent->action()->parent()) { // Parent is the regular menu. + menu->installEventFilter(this); + } + } + } } return QObject::eventFilter(watched, event); |
