I want to be able to show ToolTips for QMenu
items (QAction
s). The best I have achieved is to connect the hovered signal of the QAction
to a QTooltip
show:
connect(action, &QAction::hovered, [=]{
QToolTip::showText(QCursor::pos(), text, this);
});
The problem is that sometimes the program will position the tooltip below the menu, specially when changing menus.
Is there any way to force the tooltip to show on top?
You can subclass
QMenu
and reimplementingQMenu::event()
to intercept theQEvent::ToolTip
event and callQToolTip::showText
to set the tooltip for the active action :Now you can use your custom menu like :