The pixmap will be switched each time the paint method is called, this is probably not what you want.
Connect the timer to a slot, where you will switch the pixmap and update the item:
/*slot*/
void Foo::timeout(){
if( this->_pixmap == pixmap1 ){
this->_pixmap = pixmap2;
} else{
this->_pixmap = pixmap1;
}
update();
}
{
painter->drawPixmap(bodyRect, this->_pixmap);
}
/*slot*/
void Foo::timeout(){
if( this->_pixmap == pixmap1 ){
this->_pixmap = pixmap2;
} else{
this->_pixmap = pixmap1;
}
update();
}
void Foo::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->drawPixmap(bodyRect, this->_pixmap);
}
To copy to clipboard, switch view to plain text mode
Now on each timeout the pixmap will be switched, and item updated, no matter how often its rendered.
Btw. If you are using Qt >= 4.6, take a look at the QGraphicsObject class.
Bookmarks