aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-05-09 15:58:26 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-05-14 06:29:42 +0000
commit13996a0c58adaf21b26ed97d5c9910cecfe7ab55 (patch)
tree2f79a2199871ee4d893af8b4b5a0694f0799f5dd
parenta2fc8ef02986e55cbb7a546736e25cb597a99edd (diff)
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 Change-Id: I58afab55cc95a1d4a637111a9cca82e6177856ff Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit 7a5bbc23150fe73f86e9eb81d252cb8ebc673784) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quicktemplates2/qquickswipeview.cpp5
-rw-r--r--tests/auto/quickcontrols2/controls/data/tst_swipeview.qml30
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)
+ }
+ }
}