vcl/inc/qt5/QtInstanceIconView.hxx | 4 ++++ vcl/qt5/QtInstanceIconView.cxx | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
New commits: commit dd9096736e2e89cc533bc04c77bf539bcc5df6bc Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Feb 13 21:31:04 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Feb 13 23:41:05 2025 +0100 tdf#130857 qt weld: Show IconView item tooltips Register the QtInstanceIconView as an event filter for the QListView that holds the items and show the tooltip text for the currently hovered item, if there is one. This works fine for the "Insert" -> "Fontwork" dialog in Writer with the qt6 VCL plugin and SAL_VCL_QT_USE_WELDED_WIDGETS=1. Change-Id: I9c6d0e3309d4303558d64e1ca83b636ac3de712e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181651 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/inc/qt5/QtInstanceIconView.hxx b/vcl/inc/qt5/QtInstanceIconView.hxx index 72338d09ecf8..dd2126c83e4a 100644 --- a/vcl/inc/qt5/QtInstanceIconView.hxx +++ b/vcl/inc/qt5/QtInstanceIconView.hxx @@ -69,11 +69,15 @@ public: virtual int n_children() const override; + virtual bool eventFilter(QObject* pObject, QEvent* pEvent) override; + private: QModelIndex modelIndex(int nPos) const; QModelIndex modelIndex(const weld::TreeIter& rIter) const; static int position(const weld::TreeIter& rIter); + bool handleToolTipEvent(QHelpEvent* pEvent); + private Q_SLOTS: void handleActivated(); void handleSelectionChanged(); diff --git a/vcl/qt5/QtInstanceIconView.cxx b/vcl/qt5/QtInstanceIconView.cxx index 59fa0cd076e6..2642d3636bf4 100644 --- a/vcl/qt5/QtInstanceIconView.cxx +++ b/vcl/qt5/QtInstanceIconView.cxx @@ -14,6 +14,9 @@ #include <vcl/qt/QtUtils.hxx> +#include <QtGui/QHelpEvent> +#include <QtWidgets/QToolTip> + // role used for the ID in the QStandardItem constexpr int ROLE_ID = Qt::UserRole + 1000; @@ -29,6 +32,9 @@ QtInstanceIconView::QtInstanceIconView(QListView* pListView) m_pSelectionModel = m_pListView->selectionModel(); assert(m_pSelectionModel); + // install event filter to handle tooltip events + m_pListView->installEventFilter(this); + connect(m_pListView, &QListView::activated, this, &QtInstanceIconView::handleActivated); connect(m_pSelectionModel, &QItemSelectionModel::selectionChanged, this, &QtInstanceIconView::handleSelectionChanged); @@ -272,6 +278,16 @@ int QtInstanceIconView::n_children() const return nChildren; } +bool QtInstanceIconView::eventFilter(QObject* pObject, QEvent* pEvent) +{ + assert(pObject == m_pListView); + + if (pEvent->type() == QEvent::ToolTip) + return handleToolTipEvent(static_cast<QHelpEvent*>(pEvent)); + + return QtInstanceWidget::eventFilter(pObject, pEvent); +} + QModelIndex QtInstanceIconView::modelIndex(int nPos) const { return m_pModel->index(nPos, 0); } QModelIndex QtInstanceIconView::modelIndex(const weld::TreeIter& rIter) const @@ -285,6 +301,23 @@ int QtInstanceIconView::position(const weld::TreeIter& rIter) return aModelIndex.row(); } +bool QtInstanceIconView::handleToolTipEvent(QHelpEvent* pHelpEvent) +{ + QModelIndex aIndex = m_pListView->indexAt(pHelpEvent->pos()); + if (!aIndex.isValid()) + return false; + + SolarMutexGuard g; + const QtInstanceTreeIter aIter(aIndex); + const QString sToolTip = toQString(signal_query_tooltip(aIter)); + if (sToolTip.isEmpty()) + return false; + + QToolTip::showText(pHelpEvent->globalPos(), sToolTip, m_pListView, + m_pListView->visualRect(aIndex)); + return true; +} + void QtInstanceIconView::handleActivated() { SolarMutexGuard g;