[PySide] Rotation handles for QGraphicsPixmapItem

Thomas Perl th.perl at gmail.com
Fri Jun 22 09:45:10 CEST 2012


Hi,

2012/6/21 Jason Augustyn <js.augustyn at gmail.com>:
> Hello, I am writing an application that will allow users to select
> images placed on a QGraphicsScene (using a custom
> QGraphicsPixmapItem). Upon selection I would like a rotation handle to
> appear on the image that the user can "grab" with the mouse and
> rotate, thus rotating the QGraphicsPixmapItem. Basically, I am looking
> for the rotation handle feature you get in PowerPoint upon selecting a
> shape. This seems like a really basic feature that many people would
> have implemented, but I cannot find any good examples on the web. Can
> anyone point me in the right direction?

Implement the mousePressEvent, mouseMoveEvent and mouseReleaseEvent on
your subclass of the QGraphicsItem. You might also need grabMouse()
and ungrabMouse() (not sure about that - I *think* it should work
without that). Once you have done that, on mouse press, calculate the
current mouse position from the center, and calculate the angle. Then,
on mouseMoveEvent, calculate the angle again (with the new mouse
coordinates). The difference of the angles will be the amount that you
need to use in setRotation() of the graphics item.

Obviously, the center that you calculate should be the same as the
transformOriginPoint (transformOriginPoint() and
setTransformOriginPoint()), otherwise it won't work correctly.

HTH :)
Thomas



More information about the PySide mailing list