Skip to content

Commit 39075c7

Browse files
tdf#130857 qt weld: Implement TreeView tooltip handling
Handle the QEvent::ToolTip event for the QTreeView's viewport. Retrieve the tooltip for the item using weld::TreeView::signal_query_tooltip and display it if it's non-empty. This makes the file path of the corresponding template show up when hovering over an item in the "File" -> "Templates" -> "Manage Templates" dialog with the list view mode enabled with SAL_VCL_QT_USE_WELDED_WIDGETS=1, in a WIP branch where support for that dialog using native Qt widgets is declared. Change-Id: Ia849a9fa6506ffbd2d74be00600e0a694f1b9efd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190317 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
1 parent d93fc2b commit 39075c7

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

vcl/inc/qt5/QtInstanceTreeView.hxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ public:
209209
static void setColumnRoles(QTreeView& rTreeView,
210210
const QList<QList<Qt::ItemDataRole>>& rDataRoles);
211211

212+
virtual bool eventFilter(QObject* pObject, QEvent* pEvent) override;
213+
212214
private:
213215
QModelIndex modelIndex(int nRow, int nCol = 0,
214216
const QModelIndex& rParentIndex = QModelIndex()) const;
@@ -221,6 +223,8 @@ private:
221223

222224
void setImage(const weld::TreeIter& rIter, const QPixmap& rPixmap, int nCol);
223225

226+
bool handleToolTipEvent(const QHelpEvent* pEvent);
227+
224228
private Q_SLOTS:
225229
void handleActivated();
226230
void handleDataChanged(const QModelIndex& rTopLeft, const QModelIndex& rBottomRight,

vcl/qt5/QtInstanceTreeView.cxx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <vcl/qt/QtUtils.hxx>
1414

1515
#include <QtWidgets/QHeaderView>
16+
#include <QtWidgets/QToolTip>
1617

1718
// role used for the ID in the QStandardItem
1819
constexpr int ROLE_ID = Qt::UserRole + 1000;
@@ -43,6 +44,9 @@ QtInstanceTreeView::QtInstanceTreeView(QTreeView* pTreeView)
4344
&QtInstanceTreeView::handleSelectionChanged);
4445
connect(m_pModel, &QSortFilterProxyModel::dataChanged, this,
4546
&QtInstanceTreeView::handleDataChanged);
47+
48+
assert(m_pTreeView->viewport());
49+
m_pTreeView->viewport()->installEventFilter(this);
4650
}
4751

4852
void QtInstanceTreeView::insert(const weld::TreeIter* pParent, int nPos, const OUString* pStr,
@@ -1097,6 +1101,14 @@ void QtInstanceTreeView::setColumnRoles(QTreeView& rTreeView,
10971101
rTreeView.setProperty(PROPERTY_COLUMN_ROLES, QVariant::fromValue(rDataRoles));
10981102
}
10991103

1104+
bool QtInstanceTreeView::eventFilter(QObject* pObject, QEvent* pEvent)
1105+
{
1106+
if (pEvent->type() == QEvent::ToolTip && pObject == m_pTreeView->viewport())
1107+
return handleToolTipEvent(static_cast<QHelpEvent*>(pEvent));
1108+
1109+
return QtInstanceWidget::eventFilter(pObject, pEvent);
1110+
}
1111+
11001112
QModelIndex QtInstanceTreeView::modelIndex(int nRow, int nCol,
11011113
const QModelIndex& rParentIndex) const
11021114
{
@@ -1158,6 +1170,23 @@ void QtInstanceTreeView::setImage(const weld::TreeIter& rIter, const QPixmap& rP
11581170
});
11591171
}
11601172

1173+
bool QtInstanceTreeView::handleToolTipEvent(const QHelpEvent* pHelpEvent)
1174+
{
1175+
QModelIndex aIndex = m_pTreeView->indexAt(pHelpEvent->pos());
1176+
if (!aIndex.isValid())
1177+
return false;
1178+
1179+
SolarMutexGuard g;
1180+
const QtInstanceTreeIter aIter(aIndex);
1181+
const QString sToolTip = toQString(signal_query_tooltip(aIter));
1182+
if (sToolTip.isEmpty())
1183+
return false;
1184+
1185+
QToolTip::showText(pHelpEvent->globalPos(), sToolTip, m_pTreeView,
1186+
m_pTreeView->visualRect(aIndex));
1187+
return true;
1188+
}
1189+
11611190
void QtInstanceTreeView::handleActivated()
11621191
{
11631192
SolarMutexGuard g;

0 commit comments

Comments
 (0)