aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Köhne <kai.koehne@qt.io>2025-05-22 12:02:49 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2025-07-25 00:03:07 +0000
commit174d3d0268b2a7105b69be204d73a5d61fca3650 (patch)
tree8622a086bfdaae9f3fb761ae8609dfbab3b207a6
parent20cfab0e0a44303e9587f8298bc7cdba1304b13f (diff)
Make it explicit that TableView's rowHeight and columnWidthProvider's can also return undefined
Change-Id: I074c817a9e29a385ba2b6b8ee32c06c84853ac99 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit 090865a11230f42069b1c5c0ef8ac251183f6f74) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit af1742c0af05b619056bd347e7ec63a71b2a067c)
-rw-r--r--src/quick/items/qquicktableview.cpp8
-rw-r--r--tests/auto/quick/qquicktableview/data/userowcolumnprovider.qml8
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp36
3 files changed, 46 insertions, 6 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index ea02fcb51d..31d2aff4d1 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -180,8 +180,8 @@
Since Qt 5.13, if you want to hide a specific column, you can return \c 0
from the \l columnWidthProvider for that column. Likewise, you can return 0
from the \l rowHeightProvider to hide a row. If you return a negative
- number, TableView will fall back to calculate the size based on the delegate
- items.
+ number or \c undefined, TableView will fall back to calculate the size based
+ on the delegate items.
\note The size of a row or column should be a whole number to avoid
sub-pixel alignment of items.
@@ -454,8 +454,8 @@
for which the TableView needs to know the width.
Since Qt 5.13, if you want to hide a specific column, you can return \c 0
- width for that column. If you return a negative number, TableView
- calculates the width based on the delegate items.
+ width for that column. If you return a negative number or \c undefined,
+ TableView calculates the width based on the delegate items.
\note The columnWidthProvider will usually be called two times when
a column is about to load (or when doing layout). First, to know if
diff --git a/tests/auto/quick/qquicktableview/data/userowcolumnprovider.qml b/tests/auto/quick/qquicktableview/data/userowcolumnprovider.qml
index 686bed12d0..e812288507 100644
--- a/tests/auto/quick/qquicktableview/data/userowcolumnprovider.qml
+++ b/tests/auto/quick/qquicktableview/data/userowcolumnprovider.qml
@@ -10,6 +10,8 @@ Item {
property alias tableView: tableView
property Component delegate: tableViewDelegate
+ property bool returnUndefinedColumnWidth: false
+ property bool returnUndefinedRowHeight: false
property bool returnNegativeColumnWidth: false
property bool returnNegativeRowHeight: false
@@ -25,12 +27,14 @@ Item {
columnWidthProvider: function(column) {
if (returnNegativeColumnWidth)
return -1
- return column + 10
+ if (!returnUndefinedColumnWidth)
+ return column + 10
}
rowHeightProvider: function(row) {
if (returnNegativeRowHeight)
return -1
- return row + 10
+ if (!returnUndefinedRowHeight)
+ return row + 10
}
}
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 57188f1a86..d450aa018c 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -106,11 +106,13 @@ private slots:
void checkColumnWidthProviderInvalidReturnValues();
void checkColumnWidthProviderNegativeReturnValue();
void checkColumnWidthProviderNotCallable();
+ void checkColumnWidthProviderUndefinedReturnValue();
void checkColumnWidthBoundToViewWidth();
void checkRowHeightWithoutProvider();
void checkRowHeightProvider();
void checkRowHeightProviderInvalidReturnValues();
void checkRowHeightProviderNegativeReturnValue();
+ void checkRowHeightProviderUndefinedReturnValue();
void checkRowHeightProviderNotCallable();
void isColumnLoadedAndIsRowLoaded();
void checkForceLayoutFunction();
@@ -641,6 +643,23 @@ void tst_QQuickTableView::checkColumnWidthProviderNegativeReturnValue()
QCOMPARE(fxItem->item->width(), 20);
}
+void tst_QQuickTableView::checkColumnWidthProviderUndefinedReturnValue()
+{
+ // Check that we fall back to use the implicit width of the delegate
+ // items if the columnWidthProvider returns an undefined.
+ LOAD_TABLEVIEW("userowcolumnprovider.qml");
+
+ auto model = TestModelAsVariant(10, 10);
+ view->rootObject()->setProperty("returnUndefinedColumnWidth", true);
+
+ tableView->setModel(model);
+
+ WAIT_UNTIL_POLISHED;
+
+ for (auto fxItem : tableViewPrivate->loadedItems)
+ QCOMPARE(fxItem->item->width(), 20);
+}
+
void tst_QQuickTableView::checkColumnWidthProviderNotCallable()
{
// Check that we fall back to use default columns widths, if you
@@ -759,6 +778,23 @@ void tst_QQuickTableView::checkRowHeightProviderNegativeReturnValue()
QCOMPARE(fxItem->item->height(), 20);
}
+void tst_QQuickTableView::checkRowHeightProviderUndefinedReturnValue()
+{
+ // Check that we fall back to use the implicit height of the delegate
+ // items if the rowHeightProvider return a negative number.
+ LOAD_TABLEVIEW("userowcolumnprovider.qml");
+
+ auto model = TestModelAsVariant(10, 10);
+ view->rootObject()->setProperty("returnUndefinedRowHeight", true);
+
+ tableView->setModel(model);
+
+ WAIT_UNTIL_POLISHED;
+
+ for (auto fxItem : tableViewPrivate->loadedItems)
+ QCOMPARE(fxItem->item->height(), 20);
+}
+
void tst_QQuickTableView::checkRowHeightProviderNotCallable()
{
// Check that we fall back to use default row heights, if you