Skip to content

Commit

Permalink
[TvShow] Fix long title in tree view
Browse files Browse the repository at this point in the history
  • Loading branch information
bugwelle committed Jun 18, 2018
1 parent 2501f19 commit 750b8c0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions smallWidgets/TvShowTreeView.cpp
Expand Up @@ -16,8 +16,9 @@ TvShowTreeView::TvShowTreeView(QWidget *parent) : QTreeView(parent)

void TvShowTreeView::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
{
if (index.model()->data(index, TvShowRoles::Type).toInt() == TypeEpisode)
if (index.model()->data(index, TvShowRoles::Type).toInt() == TypeEpisode) {
return;
}

painter->save();

Expand Down Expand Up @@ -119,11 +120,14 @@ void TvShowTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &opti
option.rect.width() - branchIndent - itemIndent,
textRowHeight);

font = index.data(Qt::FontRole).value<QFont>();
painter->setPen(index.data(isSelected ? TvShowRoles::SelectionForeground : Qt::ForegroundRole).value<QColor>());
painter->setFont(index.data(Qt::FontRole).value<QFont>());
painter->drawText(showRect, index.data(Qt::DisplayRole).toString(), QTextOption(Qt::AlignVCenter));
painter->setFont(font);

const QFontMetrics metrics(font);
const QString itemStr = metrics.elidedText(index.data().toString(), Qt::ElideRight, showRect.width());
painter->drawText(showRect, itemStr, QTextOption(Qt::AlignVCenter));

font = painter->font();
#ifdef Q_OS_MAC
font.setPointSize(font.pointSize() - 2);
#else
Expand Down

0 comments on commit 750b8c0

Please sign in to comment.