Qt animation filtering

I am trying to animate QGraphicsItem, but I cannot find a way to get rid of the flicker. The element has a list of points (1.000+) and draws a polyline made from these points (for example, an electrocardiogram). I tried using double buffering (line drawing on pixmap) and then animation, but there is still flicker. Here is the code for the item

Graph::Graph(float *data,int length,int frequency,QGraphicsItem *parent) : QGraphicsItem(parent),data(data)
{
    this->path = new QPainterPath();
    this->pixmap = new QPixmap(3*length,100);
    QPainter *p = new QPainter(pixmap);
    for (int i=0; i<length; i++){
        path->lineTo(3*i,data[i]);
    }
    pixmap->fill(Qt::black);
    p->setPen(Qt::white);
    p->drawPath(*path);
    setCacheMode(DeviceCoordinateCache);
}

and drawing method

void Graph::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){

    QRectF area = option->exposedRect.toRect();
    painter->drawPixmap(area,*pixmap,area);
}

I am using QProperty animation

QPropertyAnimation* animation = new QPropertyAnimation(graph, "pos");
animation->setDuration(70000);
animation->setStartValue(QPointF(0,0));
animation->setEndValue(QPointF(-1500,0));
animation->start();

Any ideas on how to improve the code?

+3
source share
1 answer

For your parent widget and the widget where the animation takes place, you can set this flag:

parentWidget.setAttribute (Qt :: WA_NoSystemBackground); animatingWidget.setAttribute (Qt :: WA_NoSystemBackground);

0
source

All Articles