From 83f49d3f4c0041bf2c74ff1ff2eb03c5d37aa1f4 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 7 Aug 2020 15:05:23 +0200 Subject: SwipeDelegate: ensure background and contentItem are resized When the geometry of a control changes, this code is called: void QQuickControl::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_D(QQuickControl); QQuickItem::geometryChange(newGeometry, oldGeometry); d->resizeBackground(); d->resizeContent(); if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width())) emit availableWidthChanged(); if (!qFuzzyCompare(newGeometry.height(), oldGeometry.height())) emit availableHeightChanged(); } SwipeDelegate works by moving the background and contentItem together when it is swiped to expose the various delegates. Because this involves setting the position of the background, the check for background's x position being 0 in QQuickControlPrivate::resizeBackground() would fail and the background would not be resized at all. Fix this by making resizeBackground() virtual and don't check the x when checking if we should set the width. Similarly, in QQuickSwipeDelegatePrivate::resizeContent(), we should set the contentItem's width instead of just repositioning and resizing it vertically. Fixes: QTBUG-85770 Pick-to: 5.15 6.0 Change-Id: I36684bf2797719db87fe93063cc7685efe594eea Reviewed-by: Volker Hilsheimer --- tests/auto/controls/data/tst_swipedelegate.qml | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml index 6788e67a..78483406 100644 --- a/tests/auto/controls/data/tst_swipedelegate.qml +++ b/tests/auto/controls/data/tst_swipedelegate.qml @@ -1713,4 +1713,39 @@ TestCase { break; } } + + function test_resizeParent() { + let container = createTemporaryObject(itemComponent, testCase, { objectName: "container", width: 100, height: 200 }) + verify(container) + + let control = swipeDelegateComponent.createObject(container, { width: Qt.binding(function() { return container.width }) }) + verify(control) + + // Resize while closed. + container.width = 200 + compare(container.width, 200) + compare(control.width, 200) + compare(control.background.width, 200) + compare(control.contentItem.width, 200 - control.leftPadding - control.rightPadding) + + // Return to original size. + container.width = 100 + compare(control.width, 100) + compare(control.background.width, 100) + compare(control.contentItem.width, 100 - control.leftPadding - control.rightPadding) + + // Swipe to the left to open. + swipe(control, 0, -1.0) + // Nothing should have changed except positions. + compare(control.width, 100) + compare(control.background.width, 100) + compare(control.contentItem.width, 100 - control.leftPadding - control.rightPadding) + + // Resize while open. + container.width = 200 + // The items should fill the width as usual. + compare(control.width, 200) + compare(control.background.width, 200) + compare(control.contentItem.width, 200 - control.leftPadding - control.rightPadding) + } } -- cgit v1.2.3