Rotate QGraphicsItem - It does not over its center

2

I'm trying to rotate a QGraphicsItem on its own center, so it does not move its center, just turn X degrees ... I can not make it happen, it changes places, as if the whole scene were spinning but the rest of the Elements do not turn ... but he turns but not over his center. I leave the code to see if they give me a hand. Thanks a thousand.

QRectF rect;
rect = engine->boundingRect();
QPointF center = rect.center();
qreal angle = grade;
QTransform t;
t.translate(center.x(), center.y());
t.rotate(angle);
t.translate(-center.x(), -center.y());
engine->setPos(t.map(engine->pos()));
engine->setRotation(engine->rotation() + angle);

Engine is the QGraphicsItem that I want to rotate on its center ...

    
asked by Emiliano Torres 31.05.2018 в 16:39
source

1 answer

1

Thanks to @Trauma's note I leave you here as I solved my problem in case someone serves you. All the code of the question I replaced simply by the following:

engine->setTransformOriginPoint(engine->boundingRect().center());
engine->setRotation(engine->rotation() - grade);
    
answered by 31.05.2018 / 19:38
source