From 4eadda5c9a2bf8e635d187e572e72e13d9f3cd7d Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 4 Apr 2016 17:58:21 +0800 Subject: [PATCH] Improve TransferListDelegate::sizeHint --- src/gui/transferlistdelegate.cpp | 18 ++++++++++-------- src/gui/transferlistdelegate.h | 5 ----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index 72dc0cb70..c23141a0e 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -215,17 +215,19 @@ QWidget* TransferListDelegate::createEditor(QWidget*, const QStyleOptionViewItem QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const { - static int iconHeight = -1; - if (iconHeight == -1) { - QIcon icon(":/icons/skin/downloading.png"); - QList icSizes(icon.availableSizes()); - iconHeight = icSizes[0].height(); + // Reimplementing sizeHint() because the 'name' column contains text+icon. + // When that WHOLE column goes out of view(eg user scrolls horizontally) + // the rows shrink if the text's height is smaller than the icon's height. + // This happens because icon from the 'name' column is no longer drawn. + + static int nameColHeight = -1; + if (nameColHeight == -1) { + QModelIndex nameColumn = index.sibling(index.row(), TorrentModel::TR_NAME); + nameColHeight = QItemDelegate::sizeHint(option, nameColumn).height(); } QSize size = QItemDelegate::sizeHint(option, index); - if (size.height() < iconHeight) - size.setHeight(iconHeight); - + size.setHeight(std::max(nameColHeight, size.height())); return size; } diff --git a/src/gui/transferlistdelegate.h b/src/gui/transferlistdelegate.h index 3b1b55758..577dd1b32 100644 --- a/src/gui/transferlistdelegate.h +++ b/src/gui/transferlistdelegate.h @@ -49,11 +49,6 @@ public: TransferListDelegate(QObject *parent); void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const; - - // Reimplementing sizeHint() because the 'name' column contains text+icon. - // When that WHOLE column goes out of view(eg user scrolls horizontally) - // the rows shrink if the text's height is smaller than the icon's height. - // This happens because icon from the 'name' column is no longer drawn. QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; private: