diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-05-07 11:36:25 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-05-20 09:00:46 +0200 |
commit | b782a8571c1d4465c6ee5821ba65e2017361a2ec (patch) | |
tree | e9b02fceab46908a53e053b09151e292fe132790 /src/quick | |
parent | 2c9dae7b22f9dc857715ca7da64185eed9523eb4 (diff) |
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.
Task-number: QTBUG-84046
Change-Id: I1893187027b45649568347ffc3ed5d4d84beaa95
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit e1b63ac3e9a1c3920dd00a862d3f12fd278124e0)
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/quick')
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index de42d42445..339d45cad8 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -1522,31 +1522,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(); |