diff options
Diffstat (limited to 'src/gui/text/qstatictext.cpp')
-rw-r--r-- | src/gui/text/qstatictext.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 10870aa..c742455 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -324,6 +324,26 @@ QStaticText::PerformanceHint QStaticText::performanceHint() const } /*! + Sets the text option structure that controls the layout process to the given \a textOption. + + \sa textOption() +*/ +void QStaticText::setTextOption(const QTextOption &textOption) +{ + detach(); + data->textOption = textOption; + data->invalidate(); +} + +/*! + Returns the current text option used to control the layout process. +*/ +QTextOption QStaticText::textOption() const +{ + return data->textOption; +} + +/*! Sets the preferred width for this QStaticText. If the text is wider than the specified width, it will be broken into multiple lines and grow vertically. If the text cannot be split into multiple lines, it will be larger than the specified \a textWidth. @@ -580,6 +600,7 @@ void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p) QTextLayout textLayout; textLayout.setText(text); textLayout.setFont(font); + textLayout.setTextOption(textOption); qreal leading = QFontMetricsF(font).leading(); qreal height = -leading; @@ -610,21 +631,26 @@ void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p) .arg(QString::number(color.blue(), 16), 2, QLatin1Char('0'))); #endif document.setDefaultFont(font); - document.setDocumentMargin(0.0); - if (textWidth >= 0.0) - document.setTextWidth(textWidth); + document.setDocumentMargin(0.0); #ifndef QT_NO_TEXTHTMLPARSER document.setHtml(text); #else document.setPlainText(text); #endif + if (textWidth >= 0.0) + document.setTextWidth(textWidth); + else + document.adjustSize(); + document.setDefaultTextOption(textOption); - document.adjustSize(); p->save(); p->translate(topLeftPosition); document.drawContents(p); p->restore(); + if (textWidth >= 0.0) + document.adjustSize(); // Find optimal size + actualSize = document.size(); } } |