summaryrefslogtreecommitdiffstats
path: root/examples/effects/fademessage/fademessage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/effects/fademessage/fademessage.cpp')
-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);