aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2022-09-06 16:42:06 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-04-17 14:59:37 +0000
commit4e535be5cf138a844da210e63470bf7c63c60529 (patch)
tree928450eedc26a65de6e9f6284803647c4bc65c6d /tests
parentae05e89189f755b04dff0c6101c9dfec4ced962c (diff)
Fix visibility of scroll bars in ScrollView
When imperatively assigning a contentItem, we need to make sure that we respect the policy of the scroll bars, otherwise they could end up visible when they shouldn't be, and vice versa. This patch also sets the ScrollView as the parent item of the contentItem, as a ListView assigned imperatively may already have a parent item, and so setContentItem_helper will not set one. When setting the parent item, we also need to ensure that the stacking order is correct, otherwise the scroll bars will be behind the contentItem and can't be interacted with. Task-number: QTBUG-106118 Change-Id: I88d342282ea6d202cbe0f776a6bf4fb1f9cadc48 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> (cherry picked from commit db8f3607e0fb640b6bc1bb69a81ecd5f937dc184) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quickcontrols/controls/data/tst_scrollview.qml25
1 files changed, 22 insertions, 3 deletions
diff --git a/tests/auto/quickcontrols/controls/data/tst_scrollview.qml b/tests/auto/quickcontrols/controls/data/tst_scrollview.qml
index 355e130d9f..5c9c6f1184 100644
--- a/tests/auto/quickcontrols/controls/data/tst_scrollview.qml
+++ b/tests/auto/quickcontrols/controls/data/tst_scrollview.qml
@@ -617,6 +617,7 @@ TestCase {
id: bindingToContentItemAndStandaloneFlickable
Item {
+ objectName: "container"
width: 200
height: 200
@@ -655,7 +656,7 @@ TestCase {
verify(verticalScrollBar.visible)
verify(horizontalScrollBar.visible)
- mouseDrag(verticalScrollBar, verticalScrollBar.width / 2, verticalScrollBar.height / 2, 0, 50)
+ mouseWheel(control, control.width / 2, control.height / 2, 0, -120)
verify(verticalScrollBar.active)
verify(horizontalScrollBar.active)
}
@@ -664,6 +665,7 @@ TestCase {
id: contentItemAssignedImperatively
Item {
+ objectName: "container"
width: 100
height: 100
@@ -689,11 +691,28 @@ TestCase {
}
// Tests that a ListView declared before the ScrollView (as the QObject destruction order
- // is relevant for the bug) and assigned imperatively to ScrollView does not cause a crash
- // on exit.
+ // is relevant for the bug) and assigned imperatively to ScrollView does not cause:
+ // - a crash on exit
+ // - scroll bars that should be hidden to be visible
function test_contentItemAssignedImperatively() {
let root = createTemporaryObject(contentItemAssignedImperatively, testCase)
verify(root)
+
+ let control = root.scrollView
+ let flickable = control.contentItem
+ compare(flickable.parent, control)
+
+ let horizontalScrollBar = control.ScrollBar.horizontal
+ let verticalScrollBar = control.ScrollBar.vertical
+ // The horizontal ScrollBar's policy is set to AlwaysOff, so it shouldn't ever be visible.
+ verify(!horizontalScrollBar.visible)
+ // The vertical ScrollBar should be visible...
+ verify(verticalScrollBar.visible)
+
+ // ... and it should become active when the ScrollView is scrolled.
+ mouseWheel(control, control.width / 2, control.height / 2, 0, -120)
+ verify(verticalScrollBar.active)
+
// Shouldn't crash.
}
}