diff options
-rw-r--r-- | src/gui/itemviews/qlistview.cpp | 14 | ||||
-rw-r--r-- | tests/auto/qlistview/tst_qlistview.cpp | 30 |
2 files changed, 40 insertions, 4 deletions
diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp index 39ca75a..1869093 100644 --- a/src/gui/itemviews/qlistview.cpp +++ b/src/gui/itemviews/qlistview.cpp @@ -1853,14 +1853,14 @@ void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step) { horizontalScrollBar()->setSingleStep(step.width() + spacing()); horizontalScrollBar()->setPageStep(viewport()->width()); - horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width() - 2 * spacing()); + horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width()); } void QCommonListViewBase::updateVerticalScrollBar(const QSize &step) { verticalScrollBar()->setSingleStep(step.height() + spacing()); verticalScrollBar()->setPageStep(viewport()->height()); - verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height() - 2 * spacing()); + verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height()); } void QCommonListViewBase::scrollContentsBy(int dx, int dy, bool /*scrollElasticBand*/) @@ -2276,6 +2276,7 @@ void QListModeViewBase::doStaticLayout(const QListViewLayoutInfo &info) const QPoint topLeft = initStaticLayout(info); QStyleOptionViewItemV4 option = viewOptions(); option.rect = info.bounds; + option.rect.adjust(info.spacing, info.spacing, -info.spacing, -info.spacing); // The static layout data structures are as follows: // One vector contains the coordinate in the direction of layout flow. @@ -2905,8 +2906,13 @@ void QIconModeViewBase::doDynamicLayout(const QListViewLayoutInfo &info) batchStartRow = info.last + 1; bool done = (info.last >= rowCount() - 1); // resize the content area - if (done || !info.bounds.contains(item->rect())) - contentsSize = QSize(rect.width(), rect.height()); + if (done || !info.bounds.contains(item->rect())) { + contentsSize = rect.size(); + if (info.flow == QListView::LeftToRight) + contentsSize.rheight() += info.spacing; + else + contentsSize.rwidth() += info.spacing; + } // resize tree int insertFrom = info.first; if (done || info.first == 0) { diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp index d2181f8..f5c32cd 100644 --- a/tests/auto/qlistview/tst_qlistview.cpp +++ b/tests/auto/qlistview/tst_qlistview.cpp @@ -123,6 +123,7 @@ private slots: void taskQTBUG_435_deselectOnViewportClick(); void taskQTBUG_2678_spacingAndWrappedText(); void taskQTBUG_5877_skippingItemInPageDownUp(); + void taskQTBUG_9455_wrongScrollbarRanges(); }; // Testing get/set functions @@ -1941,5 +1942,34 @@ void tst_QListView::taskQTBUG_5877_skippingItemInPageDownUp() } } +class ListView_9455 : public QListView +{ +public: + QSize contentsSize() const + { + return QListView::contentsSize(); + } +}; + +void tst_QListView::taskQTBUG_9455_wrongScrollbarRanges() +{ + QStringList list; + const int nrItems = 8; + for (int i = 0; i < nrItems; i++) + list << QString().sprintf("item %d", i); + + QStringListModel model(list); + ListView_9455 w; + w.setModel(&model); + w.setViewMode(QListView::IconMode); + w.resize(116, 132); + w.setMovement(QListView::Static); + const int spacing = 40; + w.setSpacing(spacing); + w.show(); + QTest::qWaitForWindowShown(&w); + QCOMPARE(w.verticalScrollBar()->maximum(), w.contentsSize().height() - w.viewport()->geometry().height()); +} + QTEST_MAIN(tst_QListView) #include "tst_qlistview.moc" |