From 7a5bbc23150fe73f86e9eb81d252cb8ebc673784 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 9 May 2022 15:58:26 +0200 Subject: [PATCH] SwipeView: position the pages adjacent to each other initially ListView only manages the positions of the visible delegates; but the children of SwipeView are instantiated at startup. When we didn't set their positions, if they are translucent, they were simply piled up on top of each other until ListView got around to positioning them during swiping. Between a055629f43cf8589ff6d69e46b2610429aaa4167 and e10de033f4c44855de7287a97e2aa651f648742e SwipeView was calling setCulled(true); we stopped doing that because of QTBUG-99547. So now it makes sense to position the delegates the same way that ListView will eventually position them... assuming there are no other special cases for custom positioning. They are still effectively "culled" by being outside the viewport, or the clip. Fixes: QTBUG-102487 Task-number: QTBUG-51078 Task-number: QTBUG-51669 Task-number: QTBUG-99547 Pick-to: 5.15 6.2 6.3 Change-Id: I58afab55cc95a1d4a637111a9cca82e6177856ff Reviewed-by: Qt CI Bot Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickswipeview.cpp | 5 ++-- .../controls/data/tst_swipeview.qml | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/quicktemplates2/qquickswipeview.cpp b/src/quicktemplates2/qquickswipeview.cpp index e41b328477..18d04d5724 100644 --- a/src/quicktemplates2/qquickswipeview.cpp +++ b/src/quicktemplates2/qquickswipeview.cpp @@ -158,11 +158,10 @@ void QQuickSwipeViewPrivate::resizeItems() qmlWarning(item) << "SwipeView has detected conflicting anchors. Unable to layout the item."; item->setProperty("_q_QQuickSwipeView_warned", true); } - if (orientation == Qt::Horizontal) - item->setY(0); + item->setPosition({i * (contentItem->width() + spacing), 0}); else - item->setX(0); + item->setPosition({0, i * (contentItem->height() + spacing)}); item->setSize(QSizeF(contentItem->width(), contentItem->height())); } } diff --git a/tests/auto/quickcontrols2/controls/data/tst_swipeview.qml b/tests/auto/quickcontrols2/controls/data/tst_swipeview.qml index c9629de906..254c876f08 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_swipeview.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_swipeview.qml @@ -686,4 +686,34 @@ TestCase { var image = grabImage(control) compare(image.pixel(3, 3), "#ffff00") } + + Component { + id: translucentPages + SwipeView { + spacing: 10 + padding: 10 + Text { text: "page 0" } + Text { text: "page 1"; font.pointSize: 16 } + Text { text: "page 2"; font.pointSize: 24 } + Text { text: "page 3"; font.pointSize: 32 } + } + } + + function test_initialPositions() { // QTBUG-102487 + const control = createTemporaryObject(translucentPages, testCase, {width: 320, height: 200}) + verify(control) + compare(control.orientation, Qt.Horizontal) + for (var i = 0; i < control.count; ++i) { + const page = control.itemAt(i) + // control.contentItem.width + control.spacing == 310; except Imagine style has contentItem.width == 320 + compare(page.x, i * 310) + compare(page.y, 0) + } + control.orientation = Qt.Vertical + for (var i = 0; i < control.count; ++i) { + const page = control.itemAt(i) + compare(page.y, i * (control.contentItem.height + control.spacing)) + compare(page.x, 0) + } + } }