You Are Here:

Community: Wiki

This page was last modified on 31 October 2009, at 08:25.

Blink the QGraphicsTextItem in QGraphicsViewWidget

From Forum Nokia Wiki

Reviewer Approved   



ID ... Creation date 7 August 2009
Platform S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition Tested on devices S60 Emulator
Category Qt for S60 Subcategory UI


Keywords (APIs, classes, methods, functions): QGraphicsTextItem,QGraphicsItem

Overview

This is code for blinking text. Where the GraphicsView is refreshed every time with the help of update() function.This function will work after several seconds of time delay.

The text is then repainted with the help of paint() method.Time delay is defined as constant so that their should be no change in value during execution of program.


Preconditions

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();
}

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fHowE5ftoE5faddE5ficonE5ftoE5ftheE5fbuttonE5finE5fE51tE5fforE5fSymbianX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZE71tQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxE71tX qfnZuserE5ftagQSxs60X qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ