Finding the center of QGraphicsPixmapItem
Hello,
I need to apply transformations in one QGraphicsPixmapItem, but i can’t find a way to
do this correctly.
I don’t know how to determine the center of the QGraphicsPixmapItem to apply setTransformOriginPoint and then setTransform.
- {
- this->setScene(scene);
- pItem = scene->addPixmap( px );
- pItem->setScale( 0.1 );
- }
- void MyClass::Rotate( qreal angle )
- {
- qreal old_angle = m_currentAngle; // m_currentAngle is a member var, with the actual angle
- m_currentAngle = angle;
- pixmapItem->setTransform( transform );
- }
The rotation occurs, but we can see the wrong “anchor point”…
3 replies
Thank you ludde,
I tried you suggestion, but the rotation has the originPoint centered at the topLeft corner.
( boundingRect().center() have no effect ) maybe we found a bug?
What resolved the case:
- transform.translate( x, y );
- transform.rotate( angle - old_angle );
- transform.translate( -x, -y );
- scene->items().at(0)->setTransform( transform );
Thank you again.
OK, I think this is because you are creating a transformation instead of using the QGraphicsItem::rotate() function. If you create and set a transformation you probably have to do the translation (moving to the center and back) yourself. So probably not a bug, but could be better documented.
Anyway, good that you found a way that works, even if it was not exactly what I suggested. :)
You must log in to post a reply. Not a member yet? Register here!


