Originally Posted by
d_stranz
I mean, derive a class from QGraphicsItem. In its paint method, you use QPainter calls to draw ellipses in the right places. By doing it this way, you have only one QGraphicsItem for
all the ellipses, not dozens of QGraphicsEllipseItems. Of course it will redraw itself completely with each paint event, but I don't think your problem is with the drawing, it is the QGraphicsScene / QGraphicsView having to update so many items in the scene with each animation step. By eliminating all of the ones for the ellipses by pushing all of them into a single item, you minimize the number of things that must be updated.
I doubt that the ellipse drawing using QPainter calls will be a bottleneck, but if it does turn out to be slower than you wish, then you could experiment with using a
QPainterPath and adding successive ellipses to it. Then your paint method consists of a single call to
QPainter::drawPath(). This would also mean that your custom graphics item doesn't need to keep track of the ellipses - your animation code simply adds a new ellipse to the path, and the path will "remember" it.
I followed your advice and noticed a major improvement.
By the way, after defining the "global" item to hold the trajectory points, i had an issue with its paint method:
void TrajectoryItem
::paint(QPainter *painter,
{
painter->drawPath(path);
}
void TrajectoryItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *,
QWidget *)
{
painter->setPen( QPen (QColor(235,145,0)));
painter->setBrush(QBrush(QColor(235,145,0)));
painter->drawPath(path);
}
To copy to clipboard, switch view to plain text mode
I was suprised to realize that the setBrush line caused a bottleneck for long trajectories. I also realized it was useless, as the QPainterPath only stored 1-sized ellipses, so i just removed it.
Aside from this case, I was wondering if there exists some way to specify default pen and brush options for an item without having to set expicitly set them at each paint() call.
Bookmarks