diff --git a/src/playlistdelegates.cpp b/src/playlistdelegates.cpp index 690077d42..fbf3a085a 100644 --- a/src/playlistdelegates.cpp +++ b/src/playlistdelegates.cpp @@ -20,6 +20,9 @@ #include #include #include +#include +#include +#include const int PlaylistDelegateBase::kMinHeight = 19; @@ -99,6 +102,42 @@ QStyleOptionViewItemV4 PlaylistDelegateBase::Adjusted(const QStyleOptionViewItem return ret; } +bool PlaylistDelegateBase::helpEvent(QHelpEvent *event, QAbstractItemView *view, + const QStyleOptionViewItem &option, + const QModelIndex &index) { + // This function is copied from QAbstractItemDelegate, and changed to show + // displayText() in the tooltip, rather than the index's naked + // Qt::ToolTipRole text. + + Q_UNUSED(option); + + if (!event || !view) + return false; + + QHelpEvent *he = static_cast(event); + QString text = displayText(index.data(), QLocale::system()); + + if (text.isEmpty() || !he) + return false; + + switch (event->type()) { + case QEvent::ToolTip: + QToolTip::showText(he->globalPos(), text, view); + return true; + + case QEvent::QueryWhatsThis: + return true; + + case QEvent::WhatsThis: + QWhatsThis::showText(he->globalPos(), text, view); + return true; + + default: + break; + } + return false; +} + QString LengthItemDelegate::displayText(const QVariant& value, const QLocale&) const { bool ok = false; diff --git a/src/playlistdelegates.h b/src/playlistdelegates.h index d4772db74..b9ade861f 100644 --- a/src/playlistdelegates.h +++ b/src/playlistdelegates.h @@ -37,6 +37,10 @@ class PlaylistDelegateBase : public QStyledItemDelegate { static const int kMinHeight; + public slots: + bool helpEvent(QHelpEvent *event, QAbstractItemView *view, + const QStyleOptionViewItem &option, const QModelIndex &index); + protected: QTreeView* view_; };