From 7c751a57313ee2a2b4c6ca5a1815c03e3a589ff2 Mon Sep 17 00:00:00 2001 From: Reinhard Raschbauer Date: Sun, 8 Nov 2020 12:33:59 +0100 Subject: 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 --- tests/auto/quick/qquicktext/tst_qquicktext.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'tests/auto/quick') 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() -- cgit v1.2.3