diff options
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativetext.cpp | 4 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp | 18 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index fdc1a71..720692c 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -1416,10 +1416,10 @@ QRectF QDeclarativeText::boundingRect() const case AlignTop: break; case AlignBottom: - rect.setY(h - rect.height()); + rect.moveTop(h - rect.height()); break; case AlignVCenter: - rect.setY((h - rect.height()) / 2); + rect.moveTop((h - rect.height()) / 2); break; } diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index 581b58c..ca6e87a 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -658,6 +658,24 @@ void tst_qdeclarativetext::verticalAlignment() } } + //confirm that bounding rect is correctly positioned. + QString componentStr = "import QtQuick 1.0\nText { height: 80; text: \"Hello\" }"; + QDeclarativeComponent textComponent(&engine); + textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QDeclarativeText *textObject = qobject_cast<QDeclarativeText*>(textComponent.create()); + QVERIFY(textObject != 0); + QRectF br = textObject->boundingRect(); + QVERIFY(br.y() == 0); + + textObject->setVAlign(QDeclarativeText::AlignVCenter); + br = textObject->boundingRect(); + QCOMPARE(qFloor(br.y()), qFloor((80.0 - br.height())/2)); + + textObject->setVAlign(QDeclarativeText::AlignBottom); + br = textObject->boundingRect(); + QCOMPARE(qFloor(br.y()), qFloor(80.0 - br.height())); + + delete textObject; } void tst_qdeclarativetext::font() |