Show the more meaningful delegate's displayText in the playlist tooltips, rather than the naked Qt::ToolTipRole text.

Update issue 267
Status: Fixed
I've fixed the strange values for numeric fields and the length field - they
should now all show the same text as shown in the playlist.
I think it's going to be harder to inhibit the tooltip if all the text is
already displayed though.
This commit is contained in:
David Sansome 2010-04-30 15:23:52 +00:00
parent 100ecedccd
commit 0fb1a02df5
2 changed files with 43 additions and 0 deletions

View File

@ -20,6 +20,9 @@
#include <QDateTime>
#include <QLineEdit>
#include <QPainter>
#include <QToolTip>
#include <QWhatsThis>
#include <QHelpEvent>
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<QHelpEvent*>(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;

View File

@ -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_;
};