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:
parent
273448fb80
commit
cc1ec9e562
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user