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
This commit is contained in:
Graham Dawes 2019-07-09 14:14:40 +01:00 committed by Vadim Zeitlin
parent 273448fb80
commit cc1ec9e562

View File

@ -11,6 +11,7 @@
#define _WX_QT_PRIVATE_TREEITEM_DELEGATE_H
#include <QtWidgets/QStyledItemDelegate>
#include <QtWidgets/QToolTip>
#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;