From ab6e3d18dd6a91fd8a7524a8a1e2664ef88942d5 Mon Sep 17 00:00:00 2001 From: tiagomscardoso Date: Mon, 23 Jun 2025 18:40:16 +0100 Subject: [PATCH] Gui: prevent hover tooltip from covering menu items (#22019) * fix #21330: prevent hover tooltip from covering menu items Instead of showing the tooltip at the mouse cursor, it is now displayed to the right of the corresponding menu option, avoiding overlap with the menu itself. * Update src/Gui/Action.cpp --------- Co-authored-by: Chris Hennes --- src/Gui/Action.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index c839412deb..8588bc4d70 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -606,9 +606,37 @@ void ActionGroup::onActivated (QAction* act) } } -void ActionGroup::onHovered (QAction *act) +/** + * Shows tooltip at the right side when hovered. + */ +void ActionGroup::onHovered(QAction *act) { - QToolTip::showText(QCursor::pos(), act->toolTip()); + const auto topLevelWidgets = QApplication::topLevelWidgets(); + QMenu* foundMenu = nullptr; + + for (QWidget* widget : topLevelWidgets) { + QList menus = widget->findChildren(); + + for (QMenu* menu : menus) { + if (menu->isVisible() && menu->actions().contains(act)) { + foundMenu = menu; + break; + } + } + + if (foundMenu) { + break; + } + + } + + if (foundMenu) { + QRect actionRect = foundMenu->actionGeometry(act); + QPoint globalPos = foundMenu->mapToGlobal(actionRect.topRight()); + QToolTip::showText(globalPos, act->toolTip(), foundMenu, actionRect); + } else { + QToolTip::showText(QCursor::pos(), act->toolTip()); + } }