aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick
diff options
context:
space:
mode:
authorReinhard Raschbauer <r.raschbauer@kabsi.at>2020-11-08 12:33:59 +0100
committerRaschbauer, Reinhard <r.raschbauer@kabsi.at>2020-11-26 20:16:12 +0100
commit7c751a57313ee2a2b4c6ca5a1815c03e3a589ff2 (patch)
tree60ed933ac8164a7ec94796445b1d52de7dfbf4ce /tests/auto/quick
parent81629021ebc8789974c2f3c142b46eef799c1a95 (diff)
Correct height properties for QQuickText with reducing lineHeight
If the property lineHeight is used to reduce the line height, either by setting a proportional factor smaller 1.0 or a pixel size smaller than the font size, the offset calculated in lineHeightOffset is not taken in to account to calculate the height properties. But the offset is used to position the the rendered text. In the current implementation the property lineHeight does not have an effect on single line texts. This change takes that into account and adds lineHeightOffset to all height properties. Fixes: QTBUG-88229 Change-Id: Iab7d9b39a4c7876c7c95e43be6846623c10b0607 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r--tests/auto/quick/qquicktext/tst_qquicktext.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
index d1716c20da..6c257e0a9d 100644
--- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp
+++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
@@ -2293,8 +2293,12 @@ void tst_qquicktext::lineHeight()
QCOMPARE(myText->lineHeightMode(), QQuickText::ProportionalHeight);
qreal h = myText->height();
+ QVERIFY(myText->lineCount() != 0);
+ const qreal h1stLine = h / myText->lineCount();
+
myText->setLineHeight(1.5);
QCOMPARE(myText->height(), qreal(qCeil(h)) * 1.5);
+ QCOMPARE(myText->contentHeight(), qreal(qCeil(h)) * 1.5);
myText->setLineHeightMode(QQuickText::FixedHeight);
myText->setLineHeight(20);
@@ -2306,11 +2310,21 @@ void tst_qquicktext::lineHeight()
qreal h2 = myText->height();
myText->setLineHeight(2.0);
- QVERIFY(myText->height() == h2 * 2.0);
+ QCOMPARE(myText->height(), h2 * 2.0);
myText->setLineHeightMode(QQuickText::FixedHeight);
myText->setLineHeight(10);
- QCOMPARE(myText->height(), myText->lineCount() * 10.0);
+ QVERIFY(myText->lineCount() > 1);
+ QCOMPARE(myText->height(), h1stLine + (myText->lineCount() - 1) * 10.0);
+ QCOMPARE(myText->contentHeight(), h1stLine + (myText->lineCount() - 1) * 10.0);
+ QCOMPARE(myText->implicitHeight(), h1stLine + (myText->lineCount() - 1) * 10.0);
+
+ myText->setLineHeightMode(QQuickText::ProportionalHeight);
+ myText->setLineHeight(0.5);
+ const qreal reducedHeight = h1stLine + (myText->lineCount() - 1) * h1stLine * 0.5;
+ QVERIFY(qAbs(myText->height() - reducedHeight) < 1.0); // allow a deviation of one pixel because the exact height depends on the font.
+ QVERIFY(qAbs(myText->contentHeight() - reducedHeight) < 1.0);
+ QVERIFY(qAbs(myText->implicitHeight() - reducedHeight) < 1.0);
}
void tst_qquicktext::implicitSize_data()