From e1b63ac3e9a1c3920dd00a862d3f12fd278124e0 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 7 May 2020 11:36:25 +0200 Subject: TableView: during layout, set item width before height Text items like TextEdit will calculate their implicit height based on the assigned width (because of word-wrap). It's therefore better to set the width of delegate items first during a layout than after, since then we also get the correct height in such (special) cases. The result is that a rows height will show all the text in a TextEdit, and not clip it. Pick-to: 5.14 5.15 Task-number: QTBUG-84046 Change-Id: I1893187027b45649568347ffc3ed5d4d84beaa95 Reviewed-by: Shawn Rutledge Reviewed-by: Mitch Curtis --- src/quick/items/qquicktableview.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src/quick/items/qquicktableview.cpp') diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 29c6f91216..29b279c8ef 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -1700,31 +1700,44 @@ void QQuickTableViewPrivate::layoutHorizontalEdge(Qt::Edge tableEdge) { int rowThatNeedsLayout; int neighbourRow; - qreal rowY; - qreal rowHeight; if (tableEdge == Qt::TopEdge) { rowThatNeedsLayout = topRow(); neighbourRow = loadedRows.keys().value(1); - rowHeight = getRowLayoutHeight(rowThatNeedsLayout); - const auto neighbourItem = loadedTableItem(QPoint(leftColumn(), neighbourRow)); - rowY = neighbourItem->geometry().top() - cellSpacing.height() - rowHeight; } else { rowThatNeedsLayout = bottomRow(); neighbourRow = loadedRows.keys().value(loadedRows.count() - 2); - rowHeight = getRowLayoutHeight(rowThatNeedsLayout); - const auto neighbourItem = loadedTableItem(QPoint(leftColumn(), neighbourRow)); - rowY = neighbourItem->geometry().bottom() + cellSpacing.height(); } + // Set the width first, since text items in QtQuick will calculate + // implicitHeight based on the text items width. for (auto c = loadedColumns.cbegin(); c != loadedColumns.cend(); ++c) { const int column = c.key(); auto fxTableItem = loadedTableItem(QPoint(column, rowThatNeedsLayout)); auto const neighbourItem = loadedTableItem(QPoint(column, neighbourRow)); const qreal columnX = neighbourItem->geometry().x(); const qreal columnWidth = neighbourItem->geometry().width(); + fxTableItem->item->setX(columnX); + fxTableItem->item->setWidth(columnWidth); + } - fxTableItem->setGeometry(QRectF(columnX, rowY, columnWidth, rowHeight)); + qreal rowY; + qreal rowHeight; + if (tableEdge == Qt::TopEdge) { + rowHeight = getRowLayoutHeight(rowThatNeedsLayout); + const auto neighbourItem = loadedTableItem(QPoint(leftColumn(), neighbourRow)); + rowY = neighbourItem->geometry().top() - cellSpacing.height() - rowHeight; + } else { + rowHeight = getRowLayoutHeight(rowThatNeedsLayout); + const auto neighbourItem = loadedTableItem(QPoint(leftColumn(), neighbourRow)); + rowY = neighbourItem->geometry().bottom() + cellSpacing.height(); + } + + for (auto c = loadedColumns.cbegin(); c != loadedColumns.cend(); ++c) { + const int column = c.key(); + auto fxTableItem = loadedTableItem(QPoint(column, rowThatNeedsLayout)); + fxTableItem->item->setY(rowY); + fxTableItem->item->setHeight(rowHeight); fxTableItem->setVisible(true); qCDebug(lcTableViewDelegateLifecycle()) << "layout item:" << QPoint(column, rowThatNeedsLayout) << fxTableItem->geometry(); -- cgit v1.2.3