[SOLVED] Graphical artefacts in QGraphicsScene
-
Hello, I am trying to apply animation to one of my objects, but when the animation occurs, there are remaining artefacts. Look at the red triangle on the picture with the "A" in it. There are some kind of afterimages:
https://www.flickr.com/photos/heatblazer/15989282299/
Here is the code I use to paint it:
this overrides paint()
@
static inline void paintForA(QPainter* qp,
const QStyleOptionGraphicsItem* qsi,
QWidget* wd, QGraphicsItem* ari ) {
static int frames = 0;
qDebug() << "paintForA() call";
QRectF rec = ari->boundingRect();
QPixmap E_png(":/resources/images/A.png");
QImage eframe = E_png.toImage();
qp->drawImage(((ActionRectItem*)ari)->getX(),
((ActionRectItem*)ari)->getY(),
eframe);}
@
And this is on advance
@
static inline void customOnAdvance2(int j, QGraphicsItem* ari) {
if ( !j ) return;
static int i = 0;
if ( i++ > 30 ) i =0;
if ( i < 15 ) {
((QGraphicsRectItem*)ari)->setPos(
((QGraphicsRectItem*)ari)
->mapToParent(0, (((ActionRectItem*)ari)->getSpeed()-1)));
} else {
((QGraphicsRectItem)ari)->setPos(
((QGraphicsRectItem*)ari)
->mapToParent(0, (((ActionRectItem*)ari)->getSpeed())));}
}
@In the main constructor:
@
...
connect(timer, SIGNAL(timeout()),
myScene, SLOT(advance()));
@
Everything moves, but leaves these afterimages. Is this some kind of double buffernig it or?
[EDIT] I`ve solved it. It appeared that I must explicitly call QWidget::update() here:
@static inline void paintForA(QPainter* qp,
const QStyleOptionGraphicsItem* qsi,
QWidget* wd, QGraphicsItem* ari ) {
static int frames = 0;
/* test for static memory */qDebug() << "paintForA() call"; QRectF rec = ari->boundingRect(); static QPixmap E_png(":/resources/images/A.png"); static QImage eframe = E_png.toImage(); qp->drawImage(((ActionRectItem*)ari)->getX(), ((ActionRectItem*)ari)->getY(), eframe);
/* the fix */ wd->update();
}
@
Now the images are gone :) Sorry. Just too fast to self answer.