From 1d6dcee6cc75b65092715acc59d4481a2dfeb5ec Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 9 Aug 2018 09:15:08 +0200 Subject: QQuickTableView: override contentWidth/Height properties TableView uses contentWidth/height to report the size of the table (this will e.g make scrollbars written for Flickable work out of the box). This value is continuously calculated, and will change/improve as more columns are loaded into view. At the same time, we want to open up for the possibility that the application can set the content width explicitly, in case it knows what the exact width should be from the start. We therefore override the contentWidth/height properties from QQuickFlickable, to be able to implement this combined behavior. This also lets us lazy build the table if the application needs to know the content size early on. The latter will also fix problems related to querying the content size from Component.onCompleted. Change-Id: Ife7ef551dc46cf15d6940e3c6dff78545a3e4330 Reviewed-by: Mitch Curtis --- .../quick/qquicktableview/tst_qquicktableview.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp') diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index 94d3a356fe..b2f4e412f1 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -96,6 +96,7 @@ private slots: void checkRowHeightProviderInvalidReturnValues(); void checkRowHeightProviderNotCallable(); void checkContentWidthAndHeight(); + void checkExplicitContentWidthAndHeight(); void noDelegate(); void countDelegateItems_data(); void countDelegateItems(); @@ -481,6 +482,24 @@ void tst_QQuickTableView::checkContentWidthAndHeight() QCOMPARE(tableView->contentHeight(), expectedFullSize); } +void tst_QQuickTableView::checkExplicitContentWidthAndHeight() +{ + // Check that you can set a custom contentWidth/Height, and that + // TableView doesn't override it while loading more rows and columns. + LOAD_TABLEVIEW("contentwidthheight.qml"); + + tableView->setContentWidth(1000); + tableView->setContentHeight(1000); + QCOMPARE(tableView->contentWidth(), 1000); + QCOMPARE(tableView->contentHeight(), 1000); + + // Flick somewhere. It should not affect the contentWidth/Height + tableView->setContentX(500); + tableView->setContentY(500); + QCOMPARE(tableView->contentWidth(), 1000); + QCOMPARE(tableView->contentHeight(), 1000); +} + void tst_QQuickTableView::noDelegate() { // Check that you can skip setting a delegate without -- cgit v1.2.3