I continue with bad performance with my QGraphicsItem in linux on a RaspberryPI3B. I understand that the problem may come here, in this paint, that when I receive a new point to draw on the path (tracker), it recreates ALL the QPainterPath again (because it generates it cubically adding points), then when the points They are thousands, it really gets very heavy and slow. The points are saved in a QVector and in the paint creates a QPainterPath putting them cubically, to form a bezier curve.
void WorkedPathGraph::paint(QPainter *painter, const
QStyleOptionGraphicsItem *item, QWidget*)
{
QPen qpen, qpenOld;
QBrush oldBrush;
qpen.setColor(QColor("yellow"));
qpen.setWidth(1);
qpen.setCosmetic(true);
qpenOld = painter->pen();
oldBrush = painter->brush();
painter->setPen(qpen);
painter->setClipRect(item->exposedRect);
painter->setBrush(QColor("yellow"));
painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
/************************************************************/
QPainterPathStroker stroker;
stroker.setWidth(_anchoLabor);
stroker.setCapStyle(Qt::FlatCap);
QPainterPath stroke;
QPainterPath path2;
path2.moveTo(points.at(0));
int i=1;
const int &maxpoints = points.size();
while (i + 2 < maxpoints) {
path2.cubicTo(points.at(i), points.at(i+1), points.at(i+2));
i += 3;
}
while (i < maxpoints) {
path2.lineTo(points.at(i));
++i;
}
stroke = stroker.createStroke(path2);
painter->drawPath(stroke);
/************************************************************/
painter->setPen(qpenOld);
painter->setBrush(oldBrush);
}
The problem, it occurs to me, is that when there are thousands of points, it draws thousands of times ... is there no way to make it incremental ?, that is, what is already drawn, what is not redraw Is there any way to do this with Qt? Thanks a thousand, this is very interesting for me. If there is something of the code that is not understood, he asks me, because it is part of a big project and I am abstracting pieces to be able to show what is happening here.