From dc420a258adfc9cf7a73cdec3826f9b2db8ae48d Mon Sep 17 00:00:00 2001 From: Mick <39217391+mick-lue@users.noreply.github.com> Date: Mon, 27 Apr 2026 08:58:17 +0200 Subject: Change IconDelegate::paintIcons to only execute when iconWidth > 0 (#2362) --- src/icondelegate.cpp | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/icondelegate.cpp b/src/icondelegate.cpp index bec7d995..90ac246b 100644 --- a/src/icondelegate.cpp +++ b/src/icondelegate.cpp @@ -44,34 +44,34 @@ IconDelegate::IconDelegate(QTreeView* view, int column, int compactSize) void IconDelegate::paintIcons(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, const QList& icons) { - int x = 4; - painter->save(); + int iconWidth = !icons.isEmpty() ? ((option.rect.width() / icons.size()) - 4) : 16; - int iconWidth = icons.size() > 0 ? ((option.rect.width() / icons.size()) - 4) : 16; - iconWidth = std::min(16, iconWidth); - - const int margin = (option.rect.height() - iconWidth) / 2; - - painter->translate(option.rect.topLeft()); - for (const QString& iconId : icons) { - if (iconId.isEmpty()) { - x += iconWidth + 4; - continue; - } - QPixmap icon; - QString fullIconId = QString("%1_%2").arg(iconId).arg(iconWidth); - if (!QPixmapCache::find(fullIconId, &icon)) { - icon = QIcon(iconId).pixmap(iconWidth, iconWidth); - if (icon.isNull()) { - log::warn("failed to load icon {}", iconId); + if (iconWidth > 0) { + painter->save(); + iconWidth = std::min(16, iconWidth); + const int margin = (option.rect.height() - iconWidth) / 2; + painter->translate(option.rect.topLeft()); + int x = 4; + for (const QString& iconId : icons) { + if (iconId.isEmpty()) { + x += iconWidth + 4; + continue; } - QPixmapCache::insert(fullIconId, icon); + QPixmap icon; + QString fullIconId = QString("%1_%2").arg(iconId).arg(iconWidth); + if (!QPixmapCache::find(fullIconId, &icon)) { + icon = QIcon(iconId).pixmap(iconWidth, iconWidth); + if (icon.isNull()) { + log::warn("failed to load icon {}", iconId); + } + QPixmapCache::insert(fullIconId, icon); + } + painter->drawPixmap(x, margin, iconWidth, iconWidth, icon); + x += iconWidth + 4; } - painter->drawPixmap(x, margin, iconWidth, iconWidth, icon); - x += iconWidth + 4; - } - painter->restore(); + painter->restore(); + } } void IconDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, -- cgit v1.3.1