我正在尝试对一个QGraphicsItem进行动画处理,但是我找不到消除闪烁的方法。该项具有点列表(1,000+),并绘制由这些点组成的折线(类似于心电图)。我尝试使用双缓冲(在pixmap上绘制线条),然后再进行动画处理,但仍然存在闪烁问题。以下是该项的代码:
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);
}
以及paint方法
void Graph::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
QRectF area = option->exposedRect.toRect();
painter->drawPixmap(area,*pixmap,area);
}
我正在使用QProperty动画
QPropertyAnimation* animation = new QPropertyAnimation(graph, "pos");
animation->setDuration(70000);
animation->setStartValue(QPointF(0,0));
animation->setEndValue(QPointF(-1500,0));
animation->start();
有没有想法来改进代码?