aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@qt.io>2022-09-14 15:39:08 +0200
committerDominik Holland <dominik.holland@qt.io>2022-09-20 07:10:04 +0000
commit3aca22d5f5fffb4a627a18aff445de565177b730 (patch)
tree94dc98db026a61173bd5aba443409bdcea50aee3
parent3ec62d9949012a4a57be1a6119298c962a700a3f (diff)
Text: Re-layout the text when a alignment is set and the height grows
When the top alignment (default) is used, a growing height can be ignored in some situations and no re-layout is needed. But once the alignment has been changed, the re-layout needs to happen, as otherwise not all anchors are updated correctly. Fixes: QTBUG-106594 Change-Id: I9ab9999f49331aadd3bb8247d520288c40b51b21 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io> (cherry picked from commit 4933bd6351feec988746af647c391c46483f049a) Reviewed-by: Dominik Holland <dominik.holland@qt.io>
-rw-r--r--src/quick/items/qquicktext.cpp2
-rw-r--r--tests/auto/quick/qquicktext/tst_qquicktext.cpp24
2 files changed, 25 insertions, 1 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp
index 207d0d20ba..f4c2816bef 100644
--- a/src/quick/items/qquicktext.cpp
+++ b/src/quick/items/qquicktext.cpp
@@ -2445,7 +2445,7 @@ void QQuickText::geometryChange(const QRectF &newGeometry, const QRectF &oldGeom
goto geomChangeDone;
if (!(widthChanged || widthMaximum) && !d->isLineLaidOutConnected()) { // only height has changed
- if (newGeometry.height() > oldGeometry.height()) {
+ if (!verticalPositionChanged && newGeometry.height() > oldGeometry.height()) {
if (!d->heightExceeded && !qFuzzyIsNull(oldGeometry.height())) {
// Height is adequate and growing, and it wasn't 0 previously.
goto geomChangeDone;
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
index 35ff634b2e..4bf0e9596c 100644
--- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp
+++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
@@ -3630,6 +3630,30 @@ void tst_qquicktext::fontSizeMode()
myText->setElideMode(QQuickText::ElideNone);
QVERIFY(QQuickTest::qWaitForItemPolished(myText));
+
+ // Growing height needs to update the baselineOffset when AlignBottom is used
+ // and text is NOT wrapped
+ myText->setVAlign(QQuickText::AlignBottom);
+ myText->setFontSizeMode(QQuickText::Fit);
+ QVERIFY(QQuickTest::qWaitForItemPolished(myText));
+
+ int baselineOffset = myText->baselineOffset();
+ myText->setHeight(myText->height() * 2);
+ QVERIFY(QQuickTest::qWaitForItemPolished(myText));
+ QVERIFY(myText->baselineOffset() > baselineOffset);
+
+ // Growing height needs to update the baselineOffset when AlignBottom is used
+ // and the text is wrapped
+ myText->setVAlign(QQuickText::AlignBottom);
+ myText->setFontSizeMode(QQuickText::Fit);
+ myText->setWrapMode(QQuickText::NoWrap);
+ myText->resetMaximumLineCount();
+ QVERIFY(QQuickTest::qWaitForItemPolished(myText));
+
+ baselineOffset = myText->baselineOffset();
+ myText->setHeight(myText->height() * 2);
+ QVERIFY(QQuickTest::qWaitForItemPolished(myText));
+ QVERIFY(myText->baselineOffset() > baselineOffset);
}
void tst_qquicktext::fontSizeModeMultiline_data()