×
Namespaces

Variants
Actions

Archived:Blink the QGraphicsTextItem in QGraphicsViewWidget

From Nokia Developer 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
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Symbian
Article
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
{
public:
MyTextItem()
{
startTimer(delay); // start a timer
drawItem = true;
}
 
void timerEvent(QTimerEvent *)
{
// no update if the item is not visible
if(!isVisible())
return;
 
drawItem = !drawItem;
update();
}
 
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);
}
}
private:
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!");
scene.addItem(&item);
item.setPos(125, 100);
 
view.show();
return app.exec();
}
This page was last modified on 11 October 2012, at 04:13.
101 page views in the last 30 days.