From dde265294fb8c48f9e0dce95d2287482ef0c0c6b Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com> Date: Thu, 24 Jan 2013 10:28:19 +0100 Subject: [PATCH] Fix alignment of Text element with implicit size In change e1d6b323d474acc5cd70fd9a0b283326316f55a0 there's an optimization which disables layouts on the QTextDocument, but the layout has to be re-enabled before we can call idealWidth() since this will be zero as long as the page size is 0x0. We simply set the page size to undefined again before calling idealWidth. Task-number: QTBUG-29262 Change-Id: I6bebe7be4c99fce0de8fc4178b5e1abc81abbe87 Reviewed-by: Michael Brasser <michael.brasser@live.com> Reviewed-by: aavit <eirik.aavitsland@digia.com> --- src/quick/items/qquicktext.cpp | 3 ++ .../data/text/text_html_center_tag.qml | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/manual/scenegraph_lancelot/data/text/text_html_center_tag.qml diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 934451e825..917eaeadd8 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -527,10 +527,13 @@ void QQuickTextPrivate::updateSize() } if (internalWidthUpdate) return; + + extra->doc->setPageSize(QSizeF()); if (q->widthValid() && (wrapMode != QQuickText::NoWrap || extra->doc->idealWidth() < q->width())) extra->doc->setTextWidth(q->width()); else extra->doc->setTextWidth(extra->doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug) + widthExceeded = extra->doc->textWidth() < extra->doc->idealWidth(); QSizeF dsize = extra->doc->size(); layedOutTextRect = QRectF(QPointF(0,0), dsize); diff --git a/tests/manual/scenegraph_lancelot/data/text/text_html_center_tag.qml b/tests/manual/scenegraph_lancelot/data/text/text_html_center_tag.qml new file mode 100644 index 0000000000..86b528f0a4 --- /dev/null +++ b/tests/manual/scenegraph_lancelot/data/text/text_html_center_tag.qml @@ -0,0 +1,35 @@ +import QtQuick 2.0 + +Item { + width: 320 + height: 480 + + Text { + id: implicitSizedText + textFormat: Text.RichText + text: "<center>Implicit size<br>----- Second line -----</center>" + anchors.centerIn: parent + color: "white" + + Rectangle { + anchors.fill: parent + z: -1 + color: "blue" + } + } + Text { + textFormat: Text.RichText + text: "<center>Explicit size<br>----- Second line -----</center>" + anchors.top: implicitSizedText.bottom + anchors.topMargin: 10 + anchors.horizontalCenter: parent.horizontalCenter + width: 300 + color: "white" + + Rectangle { + anchors.fill: parent + z: -1 + color: "blue" + } + } +} -- GitLab