vcl/inc/qt5/QtMenu.hxx | 2 -- vcl/qt5/QtMenu.cxx | 36 ++---------------------------------- 2 files changed, 2 insertions(+), 36 deletions(-)
New commits: commit 35d1c4267dae6452a12be85f680020b69939762d Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Feb 8 11:06:29 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Feb 8 13:17:12 2025 +0100 qt: Let Qt take care of showing menu item tooltips While Qt doesn't show tooltips for QActions set in QMenu by default, this can explicitly be enabled using QtMenu::setToolTipsVisible. Use this to simplify the solution initially implemented in commit a108fce773d46441e30dcc14abe29751410ae4ed Author: Michael Weghorn <m.wegh...@posteo.de> Date: Fri Jan 17 14:18:30 2025 +0100 tdf#163186 qt: Show menu item tooltips that was using a custom event filter to show tooltips. Change-Id: I1e9719e59111d0e43059ba632e88f8ddf77be642 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181289 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/vcl/inc/qt5/QtMenu.hxx b/vcl/inc/qt5/QtMenu.hxx index 09cd015463cd..3114bd969442 100644 --- a/vcl/inc/qt5/QtMenu.hxx +++ b/vcl/inc/qt5/QtMenu.hxx @@ -74,8 +74,6 @@ public: QtMenu(bool bMenuBar); ~QtMenu(); - bool eventFilter(QObject* pObject, QEvent* pEvent) override; - virtual bool VisibleMenuBar() override; // must return TRUE to actually DISPLAY native menu bars virtual void InsertItem(SalMenuItem* pSalMenuItem, unsigned nPos) override; diff --git a/vcl/qt5/QtMenu.cxx b/vcl/qt5/QtMenu.cxx index c9c98456a921..2992baac9d70 100644 --- a/vcl/qt5/QtMenu.cxx +++ b/vcl/qt5/QtMenu.cxx @@ -32,7 +32,6 @@ #include <QtWidgets/QShortcut> #endif #include <QtWidgets/QStyle> -#include <QtWidgets/QToolTip> #include <o3tl/safeint.hxx> #include <vcl/svapp.hxx> @@ -70,37 +69,6 @@ QtMenu::QtMenu(bool bMenuBar) { } -bool QtMenu::eventFilter(QObject* pObject, QEvent* pEvent) -{ - // manually trigger tooltip if action's tooltip is set, - // Qt doesn't do that for menu entries - if (pEvent->type() != QEvent::ToolTip) - return false; - - QAction* pAction = nullptr; - if (QMenu* pMenu = qobject_cast<QMenu*>(pObject)) - pAction = pMenu->activeAction(); - else if (QMenuBar* pMenuBar = qobject_cast<QMenuBar*>(pObject)) - pAction = pMenuBar->activeAction(); - - if (!pAction) - return false; - - // QAction::toolTip() is by default based on action's text, only display if it differs - const QString sToolTip = pAction->toolTip(); - if (!sToolTip.isEmpty() && sToolTip != QAction(pAction->text()).toolTip()) - { - QHelpEvent* pHelpEvent = static_cast<QHelpEvent*>(pEvent); - QToolTip::showText(pHelpEvent->globalPos(), pAction->toolTip()); - } - else - { - QToolTip::hideText(); - } - - return false; -} - bool QtMenu::VisibleMenuBar() { return true; } void QtMenu::InsertMenuItem(QtMenuItem* pSalMenuItem, unsigned nPos) @@ -893,8 +861,8 @@ void QtMenu::connectHelpSignalSlots(QMenu* pMenu, QtMenuItem* pSalMenuItem) // connect slot to handle Help key (F1) connectHelpShortcut(pMenu); - // install event filter in order to show tooltip on tooltip event - pMenu->installEventFilter(this); + // enable tooltips, Qt doesn't show them for menu entries by default + pMenu->setToolTipsVisible(true); } void QtMenu::RemoveMenuBarButton(sal_uInt16 nId) { ImplRemoveMenuBarButton(nId); }