| 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 |
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.
#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();
}
No related wiki articles found