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>bb10
parent
dd58ddd5d9
commit
046622cdf3
|
|
@ -662,9 +662,6 @@ void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p,
|
|||
document.documentLayout()->draw(p, ctx);
|
||||
p->restore();
|
||||
|
||||
if (textWidth >= 0.0)
|
||||
document.adjustSize(); // Find optimal size
|
||||
|
||||
actualSize = document.size();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue