From 937ded010b09250c6ab9a57917f2e430fb5875f5 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 28 Oct 2017 19:13:58 +0200 Subject: QListView: make sure to respect grid size during dataChanged() handling When the dataChanged() signal is handled by QIconModeViewBase, the size of the items are recalculated. During this operation the optional grid size is not taken into account which leads to a screwed up layout. This patch adds the missing check similar it is done in doStaticLayout()/doDynamicLayout(). Task-number: QTBUG-45427 Change-Id: Iba7adb44b1510c511a69c289ccb4f168992a6871 Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qlistview.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 9e959c8e1e..9217fec10e 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -2874,10 +2874,19 @@ void QIconModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand) void QIconModeViewBase::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { if (column() >= topLeft.column() && column() <= bottomRight.column()) { - QStyleOptionViewItem option = viewOptions(); - int bottom = qMin(items.count(), bottomRight.row() + 1); + const QStyleOptionViewItem option = viewOptions(); + const int bottom = qMin(items.count(), bottomRight.row() + 1); + const bool useItemSize = !dd->grid.isValid(); for (int row = topLeft.row(); row < bottom; ++row) - items[row].resize(itemSize(option, modelIndex(row))); + { + QSize s = itemSize(option, modelIndex(row)); + if (!useItemSize) + { + s.setWidth(qMin(dd->grid.width(), s.width())); + s.setHeight(qMin(dd->grid.height(), s.height())); + } + items[row].resize(s); + } } } -- cgit v1.2.3