Fix delegate loading issue when valid size is specified

The patchset ebefb583c8 is made to avoid
loading delegate when view port size is zero. But this affects the
scenario when any of its size is valid in delegates.

This patchset fixes delegate loading issue when valid size is specified
in it.

Fixes: QTBUG-113852
Pick-to: 6.5
Change-Id: Ib8b527175b91fefb8062f7ea5abc0c9b7860a0e7
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Santhosh Kumar 2023-05-29 21:31:29 +02:00
parent cdd7fe05f6
commit 79e46dd07c
3 changed files with 51 additions and 2 deletions

View File

@ -2072,7 +2072,10 @@ void QQuickTableViewPrivate::updateContentWidth()
if (loadedItems.isEmpty()) {
QBoolBlocker fixupGuard(inUpdateContentSize, true);
q->QQuickFlickable::setContentWidth(0);
if (model && model->count() > 0 && tableModel && tableModel->delegate())
q->QQuickFlickable::setContentWidth(kDefaultColumnWidth);
else
q->QQuickFlickable::setContentWidth(0);
return;
}
@ -2105,7 +2108,10 @@ void QQuickTableViewPrivate::updateContentHeight()
if (loadedItems.isEmpty()) {
QBoolBlocker fixupGuard(inUpdateContentSize, true);
q->QQuickFlickable::setContentHeight(0);
if (model && model->count() > 0 && tableModel && tableModel->delegate())
q->QQuickFlickable::setContentHeight(kDefaultRowHeight);
else
q->QQuickFlickable::setContentHeight(0);
return;
}

View File

@ -0,0 +1,31 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
import QtQuick
import QtQuick.Window
Item {
width: 640
height: 450
property alias tableView: tableView
TableView {
id: tableView
anchors.top: parent.top
anchors.left: parent.left
anchors.bottom: parent.bottom
width: contentWidth
delegate: tableViewDelegate
}
Component {
id: tableViewDelegate
Rectangle {
objectName: "tableViewDelegate"
implicitWidth: tableView.width
implicitHeight: 50
}
}
}

View File

@ -87,6 +87,7 @@ private slots:
void checkZeroSizedDelegate();
void checkImplicitSizeDelegate();
void checkZeroSizedTableView();
void checkZeroSizedViewPort();
void checkColumnWidthWithoutProvider();
void checkColumnWidthAndRowHeightFunctions();
void checkDelegateWithAnchors();
@ -460,6 +461,17 @@ void tst_QQuickTableView::checkZeroSizedTableView()
QCOMPARE(tableViewPrivate->loadedItems.size(), 1);
}
void tst_QQuickTableView::checkZeroSizedViewPort()
{
LOAD_TABLEVIEW("zerosizedviewport.qml");
auto model = TestModelAsVariant(20, 20);
tableView->setModel(model);
WAIT_UNTIL_POLISHED;
QVERIFY(!tableViewPrivate->loadedItems.isEmpty());
}
void tst_QQuickTableView::checkColumnWidthWithoutProvider()
{