[Solved] Custom QGraphicsItem paint problem
I have a class that inherits QGraphicsItem and QObject:
@class Foo: public QObject, public QGraphicsItem
I have set up a QTimer, and connects its timeout signal with QGraphicsScene's advance.
I want to display 2 constantly shifting QPixmap on a Foo instance when it is shown:
@void Foo::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
painter->drawPixmap(bodyRect, animate?pic1:pic2); // animate is a boolean variable.
if(animate) animate = false;
else animate = true;
e.g., imagine a character walking animation with left foot pixmap and right foot pixmap.
My problem is, the result shown is not as what i have expected.
it looks like pic1 is drawn above pic2 or vice versa.
( pic1 and pic2 is a .png file, supports transparent background. does that have any effect :? )
is it impossible to make this, via paint function re-implementation?
(i'm doing this for learning purposes)
Thanks for your help and attention!
Solved! I used update() in a separate function/ slot.
Thank you! :)