Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Archived:Blink the QGraphicsTextItem in QGraphicsViewWidget

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.

This code snippet shows how to blink text (a QGraphicsTextItem) in a QGraphicsViewWidget. The GraphicsView is refreshed with the help of update() function. The text is then repainted with the help of paint() method.

Article Metadata
Tested with
Devices(s): S60 Emulator
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Keywords: QGraphicsTextItem,QGraphicsItem
Created: mind_freak (06 Aug 2009)
Last edited: hamishwillee (11 Oct 2012)

Code Snippet

Main cpp

#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsTextItem>
const int delay = 200;//set delay as per required
class MyTextItem : public QGraphicsTextItem
startTimer(delay); // start a timer
drawItem = true;
void timerEvent(QTimerEvent *)
// no update if the item is not visible
drawItem = !drawItem;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
if (drawItem) {
// call the parent's implementation to draw the text
QGraphicsTextItem::paint(painter, option, widget);
bool drawItem;
int main(int argc, char *argv[])
QApplication app(argc, argv);
QGraphicsScene scene(0,0, 400,320);
QGraphicsView view(&scene);
MyTextItem item;
item.setPlainText("Qt rocks on Symbian!");
item.setPos(125, 100);;
return app.exec();
This page was last modified on 11 October 2012, at 01:13.
54 page views in the last 30 days.