Артефакты отрисовки при использовании QGraphicsView в Qt 5 c++
При использовании QT для вывода графики наткнулся на проблему: когда прорисовываются множество объектов, привязанных к перемещающейся локальной системе координат, то после их отрисовки остаются "следы" (см. скриншот).
Хотелось бы узнать, чем может быть вызван подобный эффект и найти способ его решения. Функции, отвечающие за графику приведены ниже.
Перегрузка функции paint:
void Object::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *){
QRectF target(0, 0, this->objectMaxSize, this->objectMaxSize);
QRectF source(0, 0, this->objectMaxSize, this->objectMaxSize);
QPixmap pixmap(pathToSpriteFile);
painter->drawPixmap(target, pixmap, source);
}
Функция advance, отвечающая за задание позиции из относительных координат (relativeCoordtinates) к точке, абсоллютных координат этой самой точки (refpoint->getGlobalCoords()) и угла:
void Object::advance(int step){
if(!step){
return;
}
// If rotation is not changed optimize function by not transforming vectors
if(this->rotation() == ownRotation + refPoint->getRotation()){
//if both rotation and position are unchanged no need to change anything at all
if(refPoint->getLastCoordinateChange().x() == 0 && refPoint->getLastCoordinateChange().y() == 0){
return;
}
QVector2D newCoords = refPoint->getGlobalCoords() + relativeCoordinates;
setPos(newCoords.x(), newCoords.y());
}
else{ // If rotation is changed, calculate new relative coordinates
QVector2D relCoordinates = this->relativeCoordinates;
//if relative vector length is zero only need to change rotation. Also avoids divide by 0 situation.
if(relCoordinates.x() != 0 || relCoordinates.y() != 0){
// angle is the difference between expected position and actual position
float angle = this->rotation() - (ownRotation + refPoint->getRotation());
//Create a point containing initial relative coordinates of an object
QPointF initialCoords = this->relativeCoordinates.toPointF();
QTransform rotationAroundCenter = QTransform();
//rotate system of coordinates and get shifted position
rotationAroundCenter.rotate(-angle);
rotationAroundCenter.translate(initialCoords.x(), initialCoords.y());
//Get coordinates out of QTransform
QPointF pointID;
QPointF resultLocation = rotationAroundCenter.map(pointID);
relCoordinates.setX(resultLocation.x());
relCoordinates.setY(resultLocation.y());
}
//set new relative coordinates vector and set new position and rotation
relativeCoordinates = relCoordinates;
QVector2D newCoordinates = refPoint->getGlobalCoords() + relativeCoordinates;
setPos(newCoordinates.x(), newCoordinates.y());
setRotation(ownRotation + refPoint->getRotation());
}
}