aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-05-07 11:36:25 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-05-08 16:51:47 +0200
commite1b63ac3e9a1c3920dd00a862d3f12fd278124e0 (patch)
tree645a1af1a52aa80dbd4e979482f8f46ef51ed702 /src/quick/items/qquicktableview.cpp
parent0c8297ecb0c6512b24e021ebdb306c5279a2f48d (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. Pick-to: 5.14 5.15 Task-number: QTBUG-84046 Change-Id: I1893187027b45649568347ffc3ed5d4d84beaa95 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quick/items/qquicktableview.cpp')
-rw-r--r--src/quick/items/qquicktableview.cpp31
1 files changed, 22 insertions, 9 deletions
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();