diff options
author | Igor Mironchik <igor.mironchik@gmail.com> | 2018-01-18 09:58:59 +0300 |
---|---|---|
committer | Igor Mironchik <igor.mironchik@gmail.com> | 2018-01-20 11:22:53 +0000 |
commit | 046622cdf3b6f856f67ab314c7758aca4dcf5494 (patch) | |
tree | 583f834d3beb9e0a3bbbcccbfb615358075edf35 /tests/auto | |
parent | dd58ddd5d97f0663d5fafb7e81bff4fc7db13ba7 (diff) |
Fix explicitly set width not being respected
The size of the QStaticText was always adjusted, even if setTextWidth()
was used. Now size of the QStaticText is calculated according to
the set width of the text, and if no width was set, then the
automatically adjusted size is used.
[ChangeLog][QtGui][QStaticText] Fixed explicitly set width not being
respected.
Task-number: QTBUG-65836
Change-Id: If2f9f6952fb168f4bcb6d8fabfdc7360f8a36485
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/gui/text/qstatictext/tst_qstatictext.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp index e3cb265ebe..45cc94afad 100644 --- a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp @@ -98,6 +98,8 @@ private slots: void multiLine(); + void size_qtbug65836(); + private: bool supportsTransformations() const; @@ -912,5 +914,42 @@ void tst_QStaticText::multiLine() QCOMPARE(paintEngine->differentVerticalPositions.size(), 2); } +void tst_QStaticText::size_qtbug65836() +{ + const QString text = QLatin1String("Lorem ipsum dolor sit amet, " + "consectetur adipiscing elit."); + QFont font("Courier"); + font.setPixelSize(15); + + { + QStaticText st1(text); + st1.setTextFormat(Qt::PlainText); + st1.prepare(QTransform(), font); + + QStaticText st2(text); + st2.setTextFormat(Qt::RichText); + QTextOption opt; + opt.setWrapMode(QTextOption::NoWrap); + st2.setTextOption(opt); + st2.prepare(QTransform(), font); + + QCOMPARE(st1.size(), st2.size()); + } + + { + QStaticText st1(text); + st1.setTextFormat(Qt::PlainText); + st1.setTextWidth(10.0); + st1.prepare(QTransform(), font); + + QStaticText st2(text); + st2.setTextFormat(Qt::RichText); + st2.setTextWidth(10.0); + st2.prepare(QTransform(), font); + + QCOMPARE(st1.size(), st2.size()); + } +} + QTEST_MAIN(tst_QStaticText) #include "tst_qstatictext.moc" |