Skip to content

Disable extra context menu in Documentation tool view

Right-clicking on a non-home page in Documentation view is supposed to show context menu entries defined in KDevelop (only "Copy" most of the time). However currently two context menus are shown when KDevelop is built with Qt WebEngine: the "Copy" one and on top of it a WebEngine's native context menu (with actions like "Back", "Forward", "Reload" or "Open link in a new tab", "Save link"). Dismissing the two context menus requires two left mouse button clicks, which is surprising and inconvenient.

Setting context menu policy to Qt::NoContextMenu in addition to the event filter workaround disables the WebEngine's native context menu.

Before: double-context-menu After: single-context-menu

The code looks weird now with #ifdef spanning across functions. A tempting alternative is to duplicate the m_view->setContextMenuPolicy(Qt::NoContextMenu); line. However I decided to implement it this way because the line above - m_view->installEventFilter(parent); - is likely to be pushed under the #endif soon since it is needed for Qt WebKit in https://invent.kde.org/kde/kdevelop/-/merge_requests/44/diffs#diff-content-c30ed0519cf54cf18c74e534e4cca7a7f358ac71 and in my own planned documentation zoom fix.

I have verified that this fix is necessary and works well with Qt 5.14.1 and Qt 5.9.7. I have also verified that it doesn't affect the context menu when KDevelop is built with Qt WebKit.

Merge request reports