#include "TrackDelegate.h" #include TrackDelegate::TrackDelegate(QObject *parent) : QStyledItemDelegate(parent) {} QSize TrackDelegate::sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const { return {0, 42}; // fixed row height } void TrackDelegate::paint(QPainter *p, const QStyleOptionViewItem &opt, const QModelIndex &idx) const { p->save(); bool selected = opt.state & QStyle::State_Selected; bool current = idx.data(Qt::UserRole + 1).toBool(); // is-playing flag QColor bg = selected ? opt.palette.highlight().color() : (idx.row() % 2 == 0 ? opt.palette.base().color() : opt.palette.alternateBase().color()); p->fillRect(opt.rect, bg); if (current) { QColor accent = opt.palette.highlight().color(); p->fillRect(opt.rect.left(), opt.rect.top(), 3, opt.rect.height(), accent); } QColor fg = selected ? opt.palette.highlightedText().color() : opt.palette.text().color(); QColor dim = selected ? fg : fg.lighter(160); int pad = current ? 10 : 7; QRect r = opt.rect.adjusted(pad, 2, -6, -2); int mid = r.top() + r.height() / 2; QFont fTop = opt.font; fTop.setBold(true); fTop.setPointSizeF(10); p->setFont(fTop); p->setPen(fg); QString title = idx.data(Qt::DisplayRole).toString(); p->drawText(r.left(), r.top(), r.width(), mid - r.top(), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, title); QFont fBot = opt.font; fBot.setPointSizeF(8.5); p->setFont(fBot); p->setPen(dim); QString sub = idx.data(Qt::UserRole).toString(); p->drawText(r.left(), mid, r.width(), r.bottom() - mid, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, sub); p->restore(); }