Skip to content

Commit 4eadda5

Browse files
committed
Improve TransferListDelegate::sizeHint
1 parent 93d8cad commit 4eadda5

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

src/gui/transferlistdelegate.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,19 @@ QWidget* TransferListDelegate::createEditor(QWidget*, const QStyleOptionViewItem
215215

216216
QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
217217
{
218-
static int iconHeight = -1;
219-
if (iconHeight == -1) {
220-
QIcon icon(":/icons/skin/downloading.png");
221-
QList<QSize> icSizes(icon.availableSizes());
222-
iconHeight = icSizes[0].height();
218+
// Reimplementing sizeHint() because the 'name' column contains text+icon.
219+
// When that WHOLE column goes out of view(eg user scrolls horizontally)
220+
// the rows shrink if the text's height is smaller than the icon's height.
221+
// This happens because icon from the 'name' column is no longer drawn.
222+
223+
static int nameColHeight = -1;
224+
if (nameColHeight == -1) {
225+
QModelIndex nameColumn = index.sibling(index.row(), TorrentModel::TR_NAME);
226+
nameColHeight = QItemDelegate::sizeHint(option, nameColumn).height();
223227
}
224228

225229
QSize size = QItemDelegate::sizeHint(option, index);
226-
if (size.height() < iconHeight)
227-
size.setHeight(iconHeight);
228-
230+
size.setHeight(std::max(nameColHeight, size.height()));
229231
return size;
230232
}
231233

src/gui/transferlistdelegate.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class TransferListDelegate: public QItemDelegate
4949
TransferListDelegate(QObject *parent);
5050
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
5151
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const;
52-
53-
// Reimplementing sizeHint() because the 'name' column contains text+icon.
54-
// When that WHOLE column goes out of view(eg user scrolls horizontally)
55-
// the rows shrink if the text's height is smaller than the icon's height.
56-
// This happens because icon from the 'name' column is no longer drawn.
5752
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
5853

5954
private:

0 commit comments

Comments
 (0)