diff options
author | Joerg Bornemann <joerg.bornemann@nokia.com> | 2009-11-11 17:52:45 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2009-11-13 12:17:03 (GMT) |
commit | 4c0b5bc7980948004b0ba30b964d252ba81113ec (patch) | |
tree | b211fa92046bd4f763bd4432d8fb33ee1883d0d0 /examples | |
parent | 7c704c3bbc80be3b1f63b56c8d4b336e2e1da1fd (diff) | |
download | Qt-4c0b5bc7980948004b0ba30b964d252ba81113ec.zip Qt-4c0b5bc7980948004b0ba30b964d252ba81113ec.tar.gz Qt-4c0b5bc7980948004b0ba30b964d252ba81113ec.tar.bz2 |
fademessage example: don't use a fixed width for the rect under the text
Its using QFontMetrics::width now.
Reviewed-by: thartman
(cherry picked from commit 4e37815e7e3c68ff561ead147cb06898a2db9c75)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/effects/fademessage/fademessage.cpp | 10 |
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); |