summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@nokia.com>2009-11-11 17:52:45 (GMT)
committerJoerg Bornemann <joerg.bornemann@nokia.com>2009-11-11 17:52:45 (GMT)
commit4e37815e7e3c68ff561ead147cb06898a2db9c75 (patch)
treefb48b26dbb780bcb73346dcf7b61d2f705a95572
parenta9576bacae07eb2b8465191a3e537a5659145914 (diff)
downloadQt-4e37815e7e3c68ff561ead147cb06898a2db9c75.zip
Qt-4e37815e7e3c68ff561ead147cb06898a2db9c75.tar.gz
Qt-4e37815e7e3c68ff561ead147cb06898a2db9c75.tar.bz2
fademessage example: don't use a fixed width for the rect under the text
Its using QFontMetrics::width now. Reviewed-by: thartman
-rw-r--r--examples/effects/fademessage/fademessage.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/examples/effects/fademessage/fademessage.cpp b/examples/effects/fademessage/fademessage.cpp
index 818d00f..28dd3bd 100644
--- a/examples/effects/fademessage/fademessage.cpp
+++ b/examples/effects/fademessage/fademessage.cpp
@@ -94,13 +94,17 @@ void FadeMessage::setupScene()
QFont font;
font.setPointSize(font.pointSize() * 2);
font.setBold(true);
- int fh = QFontMetrics(font).height();
+ QFontMetrics fontMetrics(font);
+ int fh = fontMetrics.height();
- QGraphicsRectItem *block = m_scene.addRect(50, 300, 300, fh + 3);
+ QString sceneText = "Qt Everywhere!";
+ int sceneTextWidth = fontMetrics.width(sceneText);
+
+ QGraphicsRectItem *block = m_scene.addRect(50, 300, sceneTextWidth, fh + 3);
block->setPen(Qt::NoPen);
block->setBrush(QColor(102, 153, 51));
- QGraphicsTextItem *text = m_scene.addText("Qt Everywhere!", font);
+ QGraphicsTextItem *text = m_scene.addText(sceneText, font);
text->setDefaultTextColor(Qt::white);
text->setPos(50, 300);
block->setZValue(2);