[frameworks/kio] src/filewidgets: KFilePlacesView: cap the icon size by the real row height

Méven Car <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 2154f75e9b6a9b6c506f5212da92a6ff31983bcb by Méven Car.
Committed on 23/07/2026 at 11:20.
Pushed by meven into branch 'master'.

KFilePlacesView: cap the icon size by the real row height

adaptItemSize() subtracted only s_lateralMargin from the per-row height budget,
but a row is taller than its icon by the item frame padding. The icons could
grow one step too tall, the rows overflowed and a vertical scrollbar appeared,
which narrowed the viewport, shrank the icons and hid the scrollbar again, so
the size jittered and the scrollbar showed up merely on widening the panel.

Subtract the real per-row overhead taken from the style so the chosen icon size
always leaves the rows fitting within the viewport.

M  +10   -1    src/filewidgets/kfileplacesview.cpp

https://invent.kde.org/frameworks/kio/-/commit/2154f75e9b6a9b6c506f5212da92a6ff31983bcb

diff --git a/src/filewidgets/kfileplacesview.cpp b/src/filewidgets/kfileplacesview.cpp
index 46153992dc..697bd3395f 100644
--- a/src/filewidgets/kfileplacesview.cpp
+++ b/src/filewidgets/kfileplacesview.cpp
@@ -1868,7 +1868,16 @@ void KFilePlacesViewPrivate::adaptItemSize()
     }
 
     const int totalSectionsHeight = m_delegate->sectionHeaderHeight(QModelIndex()) * sectionsCount();
-    const int maxHeight = qCeil((q->height() - totalSectionsHeight) / rowCount) - s_lateralMargin;
+
+    // Height a row needs beyond the icon (item frame padding), from the style, so the chosen
+    // icon size leaves all rows fitting the viewport and does not force a scrollbar.
+    QStyleOptionViewItem rowOption;
+    rowOption.initFrom(q);
+    rowOption.features |= QStyleOptionViewItem::HasDecoration;
+    rowOption.decorationSize = QSize(maxSize, maxSize);
+    const int rowOverhead = q->style()->sizeFromContents(QStyle::CT_ItemViewItem, &rowOption, {}, q).height() - maxSize;
+
+    const int maxHeight = (q->height() - totalSectionsHeight) / rowCount - rowOverhead;
 
     int size = qMin(maxHeight, maxWidth);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.