diff options
-rw-r--r-- | src/controls/Private/ScrollViewHelper.qml | 18 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_scrollview.qml | 26 |
2 files changed, 25 insertions, 19 deletions
diff --git a/src/controls/Private/ScrollViewHelper.qml b/src/controls/Private/ScrollViewHelper.qml index 810de91d..53050108 100644 --- a/src/controls/Private/ScrollViewHelper.qml +++ b/src/controls/Private/ScrollViewHelper.qml @@ -68,31 +68,29 @@ Item { anchors.fill: parent - property bool recursionGuard: false - - function doLayout() { - if (!recursionGuard) { - recursionGuard = true + Timer { + id: layoutTimer + interval: 0; + onTriggered: { blockUpdates = true; scrollHelper.contentWidth = flickableItem !== null ? flickableItem.contentWidth : 0 scrollHelper.contentHeight = flickableItem !== null ? flickableItem.contentHeight : 0 scrollHelper.availableWidth = viewport.width scrollHelper.availableHeight = viewport.height blockUpdates = false; - recursionGuard = false } } Connections { target: viewport - onWidthChanged: doLayout() - onHeightChanged: doLayout() + onWidthChanged: layoutTimer.running = true + onHeightChanged: layoutTimer.running = true } Connections { target: flickableItem - onContentWidthChanged: doLayout() - onContentHeightChanged: doLayout() + onContentWidthChanged: layoutTimer.running = true + onContentHeightChanged: layoutTimer.running = true onContentXChanged: { hscrollbar.flash() vscrollbar.flash() diff --git a/tests/auto/controls/data/tst_scrollview.qml b/tests/auto/controls/data/tst_scrollview.qml index 42398115..d3bfac4b 100644 --- a/tests/auto/controls/data/tst_scrollview.qml +++ b/tests/auto/controls/data/tst_scrollview.qml @@ -212,21 +212,27 @@ TestCase { bigItem.height = 100 bigItem.width = 100 - verify(!scrollView.__horizontalScrollBar.visible, "Scrollbar showing when contents already fit") - verify(!scrollView.__verticalScrollBar.visible, "Scrollbar showing when contents already fit") + tryVerify(function() { return !scrollView.__horizontalScrollBar.visible }, 50, + "Scrollbar showing when contents already fit") + tryVerify(function() { return !scrollView.__verticalScrollBar.visible }, 50, + "Scrollbar showing when contents already fit") bigItem.height = 1000 bigItem.width = 1000 - verify(scrollView.__horizontalScrollBar.visible, "Scrollbar not showing when contents are too big") - verify(scrollView.__verticalScrollBar.visible, "Scrollbar not showing when contents are too big") + tryVerify(function() { return scrollView.__horizontalScrollBar.visible }, 50, + "Scrollbar not showing when contents are too big") + tryVerify(function() { return scrollView.__verticalScrollBar.visible }, 50, + "Scrollbar not showing when contents are too big") //always off bigItem.height = 1000 scrollView.verticalScrollBarPolicy = Qt.ScrollBarAlwaysOff - verify(!scrollView.__verticalScrollBar.visible, "Scrollbar showing when disabled") + tryVerify(function() { return !scrollView.__verticalScrollBar.visible }, 50, + "Scrollbar showing when disabled") bigItem.height = 100 - verify(!scrollView.__verticalScrollBar.visible, "Scrollbar showing when disabled") + tryVerify(function() { return !scrollView.__verticalScrollBar.visible }, 50, + "Scrollbar showing when disabled") //always on scrollView.verticalScrollBarPolicy = Qt.ScrollBarAlwaysOn @@ -258,12 +264,14 @@ TestCase { verify(scrollView !== null, "view created is null") verify(scrollView.flickableItem.contentY === 0) + tryVerify(function() { return scrollView.__verticalScrollBar.visible }); + mouseClick(scrollView, scrollView.width -2, scrollView.height/2, Qt.LeftButton) - verify(Math.round(scrollView.flickableItem.contentY) === 100) + tryVerify(function() { return Math.round(scrollView.flickableItem.contentY) === 100 }); - verify(scrollView.flickableItem.contentX === 0) + tryVerify(function() { return scrollView.flickableItem.contentX === 0 }) mouseClick(scrollView, scrollView.width/2, scrollView.height - 2, Qt.LeftButton) - verify(Math.round(scrollView.flickableItem.contentX) === 100) + tryVerify(function() { return Math.round(scrollView.flickableItem.contentX) === 100 }) } function test_viewport() { |