Solved Have a problem with rotation of QGraphicsRectItem
-
I created class MyRect that inhertis from QGraphicsRectItem and my goal is
to rotate rect in center by 10 degree when user press left or right key but problem
is that rect rotate only once after second press on key it wont and rotation is not in center of rectvoid MyRect::keyPressEvent(QKeyEvent *event)
{if(event->key()==Qt::Key_Left) { setRotation(-10); // setPos(x()-10,y()); } else if(event->key()==Qt::Key_Right) { setRotation(10); // setPos(x()+10,y()); }
}
-
Because you're setting the rotation explicitly to +/- 10 degree as described in the documentation
"Sets the clockwise rotation angle, in degrees, around the Z axis. The default value is 0 (i.e., the item is not rotated). Assigning a negative value will rotate the item counter-clockwise. " -
@Christian-Ehrlicher
I find how to rotate with this setRotation(rotation()+10); now how to rotate in center of rect not of the top left corner and thank you -
This also is described in the documentation two lines below ...
-
@Christian-Ehrlicher Thank you i solve my problem with this
setTransformOriginPoint(QPoint(50,50));
setRotation(rotation()-10);