From cc1ec9e56201a84b5c7bb299b19d5e825c9aca3f Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Tue, 9 Jul 2019 14:14:40 +0100 Subject: [PATCH] Show tooltip in wxTreeCtrl when item text doesn't fit on screen This matches the behaviour of the native control in wxMSW and is generally useful. Closes https://github.com/wxWidgets/wxWidgets/pull/1397 --- include/wx/qt/private/treeitemdelegate.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/wx/qt/private/treeitemdelegate.h b/include/wx/qt/private/treeitemdelegate.h index 65025de442..632172f6ec 100644 --- a/include/wx/qt/private/treeitemdelegate.h +++ b/include/wx/qt/private/treeitemdelegate.h @@ -11,6 +11,7 @@ #define _WX_QT_PRIVATE_TREEITEM_DELEGATE_H #include +#include #include "wx/app.h" #include "wx/textctrl.h" @@ -67,6 +68,28 @@ public: QStyledItemDelegate::setModelData(editor, model, index); } + bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) + { + if ( event->type() == QEvent::ToolTip ) + { + const QRect &itemRect = view->visualRect(index); + const QSize &bestSize = sizeHint(option, index); + if ( itemRect.width() < bestSize.width() ) + { + const QString &value = index.data(Qt::DisplayRole).toString(); + QToolTip::showText(event->globalPos(), value, view); + } + else + { + QToolTip::hideText(); + } + + return true; + } + + return QStyledItemDelegate::helpEvent(event, view, option, index); + } + private: wxWindow* m_parent; mutable wxTextCtrl* m_textCtrl;