Make showing tool tips for menu items more widely available

Change-Id: Ic9fcb61917c955a2b114c3a355dbdf5c291d75f3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Eike Ziller
2023-07-11 13:54:30 +02:00
parent 5b79efd0d6
commit 9144706000
3 changed files with 17 additions and 5 deletions

View File

@@ -3,6 +3,8 @@
#include "execmenu.h"
#include "tooltip/tooltip.h"
#include <QMenu>
#include <QPoint>
#include <QRect>
@@ -41,4 +43,14 @@ QAction *execMenuAtWidget(QMenu *menu, QWidget *widget)
return menu->exec(p);
}
/*!
Adds tool tips to the menu that show the actions tool tip when hovering over an entry.
*/
void addToolTipsToMenu(QMenu *menu)
{
QObject::connect(menu, &QMenu::hovered, menu, [menu](QAction *action) {
ToolTip::show(menu->mapToGlobal(menu->actionGeometry(action).topRight()), action->toolTip());
});
}
} // namespace Utils

View File

@@ -14,5 +14,6 @@ QT_END_NAMESPACE
namespace Utils {
QTCREATOR_UTILS_EXPORT QAction *execMenuAtWidget(QMenu *menu, QWidget *widget);
QTCREATOR_UTILS_EXPORT void addToolTipsToMenu(QMenu *menu);
} // namespace Utils

View File

@@ -13,6 +13,7 @@
#include "../modemanager.h"
#include <utils/algorithm.h>
#include <utils/execmenu.h>
#include <utils/fancylineedit.h>
#include <utils/fsengine/fileiconprovider.h>
#include <utils/highlightingitemdelegate.h>
@@ -22,7 +23,6 @@
#include <utils/qtcassert.h>
#include <utils/tooltip/tooltip.h>
#include <utils/utilsicons.h>
#include <QAction>
#include <QApplication>
#include <QColor>
@@ -584,13 +584,12 @@ LocatorWidget::LocatorWidget(Locator *locator)
m_centeredPopupAction->setCheckable(true);
m_centeredPopupAction->setChecked(Locator::useCenteredPopupForShortcut());
connect(m_filterMenu, &QMenu::aboutToShow, this, [this] {
m_centeredPopupAction->setChecked(Locator::useCenteredPopupForShortcut());
});
connect(m_filterMenu, &QMenu::hovered, this, [this](QAction *action) {
ToolTip::show(m_filterMenu->mapToGlobal(m_filterMenu->actionGeometry(action).topRight()),
action->toolTip());
});
Utils::addToolTipsToMenu(m_filterMenu);
connect(m_centeredPopupAction, &QAction::toggled, locator, [locator](bool toggled) {
if (toggled != Locator::useCenteredPopupForShortcut()) {
Locator::setUseCenteredPopupForShortcut(toggled);