aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-11-22 11:21:57 +0100
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-11-27 09:50:19 +0000
commit343cea9b49d7afa7614aea27aed7c48ef9c5be2e (patch)
tree6d028cbd7ba1fbd1e015579964b37364b4f4f5fb /tests
parent8317e62c3e2381e6287c9a7e861d20f78aaea03f (diff)
QQuickScrollView: override getContentWidth/Height()
A ScrollView lets you add the Flickable that should be decorated as a child. If that flickable has one (and only one) child, the contentWidth/Height properties of the ScrollView will be calculated by using the implicit size of that child (unless you assign something else to those properties explicitly). This logic goes wrong when the flickable is a TableView for several reasons. The first is that TableView will populate the content item dynamically, and for the first delegate item added, the content size of the ScrollView will be set to be the size of this item (since the TableView only got one child at that point). The second is that TableView has its own set of contentWidth/Height properties. And those properties are not respected by ScrollView. So even if TableView set the contentWidth/Height to be the size of the table, this will not be used by ScrollView. The result is that ScrollView concludes that the content item is empty, which means that no scrollbars end up visible or usable. This patch will fix this by overriding getContentWidth()/Height() from QQuickPane. The implementation will check if the flickable has valid contentWidth/Height values set, and if so, use them. Otherwise it will fall back to the old QQuickPane implementation (which will inspect the children etc). Fixes: QTBUG-71974 Change-Id: I027b9b939a10df2aeb816dea596adcb452f914b9 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: J-P Nurmi <jpnurmi@gmail.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/controls/data/tst_scrollview.qml49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_scrollview.qml b/tests/auto/controls/data/tst_scrollview.qml
index 80110b5a..a06072e5 100644
--- a/tests/auto/controls/data/tst_scrollview.qml
+++ b/tests/auto/controls/data/tst_scrollview.qml
@@ -118,6 +118,22 @@ TestCase {
}
Component {
+ id: emptyFlickable
+ ScrollView {
+ Flickable {
+ }
+ }
+ }
+
+ Component {
+ id: labelComponent
+ Label {
+ text: "ABC"
+ font.pixelSize: 512
+ }
+ }
+
+ Component {
id: scrollableListView
ScrollView {
ListView {
@@ -241,6 +257,39 @@ TestCase {
compare(control.contentHeight, listview.contentHeight)
}
+ function test_flickableWithExplicitContentSize() {
+ var control = createTemporaryObject(emptyFlickable, testCase)
+ verify(control)
+
+ var flickable = control.contentItem
+ verify(flickable.hasOwnProperty("contentX"))
+ verify(flickable.hasOwnProperty("contentY"))
+
+ var flickableContentSize = 1000;
+ flickable.contentWidth = flickableContentSize;
+ flickable.contentHeight = flickableContentSize;
+
+ compare(flickable.contentWidth, flickableContentSize)
+ compare(flickable.contentHeight, flickableContentSize)
+ compare(control.implicitWidth, flickableContentSize)
+ compare(control.implicitHeight, flickableContentSize)
+ compare(control.contentWidth, flickableContentSize)
+ compare(control.contentHeight, flickableContentSize)
+
+ // Add a single child to the flickable. This should not
+ // trick ScrollView into taking the implicit size of
+ // the child as content size, since the flickable
+ // already has an explicit content size.
+ labelComponent.createObject(flickable);
+
+ compare(flickable.contentWidth, flickableContentSize)
+ compare(flickable.contentHeight, flickableContentSize)
+ compare(control.implicitWidth, flickableContentSize)
+ compare(control.implicitHeight, flickableContentSize)
+ compare(control.contentWidth, flickableContentSize)
+ compare(control.contentHeight, flickableContentSize)
+ }
+
function test_mouse() {
var control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200, contentHeight: 400})
verify(control)