PDA

View Full Version : Rotate Item qgraphicsscene



pispipepe
22nd June 2010, 20:16
Hello

I try to rotate a item, the item was added in a graphicsscene, add the image jpg before the circle, i add the circle with mousepresevent with parameters xmouse and ymouse.

http://img132.imageshack.us/img132/5070/clipboard01zw.jpg (http://img132.imageshack.us/i/clipboard01zw.jpg/)


the promlem when i rotate the item (circle) the rotating point it uses is the point 0,0 of the image jpg, as it shows in the image.

numbers in the image
1.- Qgraphicsscene inside the Qgraphicsview
2.- Image JPG
3.-Item (circle) rotate fine
4.-Item (circle) rotate wrong



a = math.pi/45* value
sina = math.sin(a)
cosa = math.cos(a)
translationTransform=QTransform(1, 0, 0, 1, 0, 0);
rotationTransform=QTransform(cosa, sina, -sina, cosa, 0, 0);
scalingTransform=QTransform(1., 0, 0, 1.0, 0, 0);
transform = scalingTransform * rotationTransform * translationTransform;
self.scene.selectedItems()[0].setTransform(transform)


How i can do to rotate the circle from the center of the circle.


Sorry for my english.

JohannesMunk
23rd June 2010, 13:33
Your approach of combining a translation and a rotation should work. But should your translation not be in item coordinates? Thus contain something like image.width()/2 ?

And I don't think that you have to calculate the rotation matrix manually. Just use:


QTransform q;
q.translate(image.width()/2,image.height()/2);
q.rotate(a);
q.translate(-image.width()/2,-image.height()/2);


This is probably not exactly right. Just guessing. You may need to swap the translations..

HIH

Johannes

pispipepe
5th July 2010, 23:57
Thanks your answer that help me, my mistake was when aadding the item


self.myObj = QGraphicsEllipseItem(QtCore.QRectF(xmouse, ymouse, ancho, alto), parent = None, scene = self.scene)

Changing xmose and ymouse for the image zero point.

And then the circle rotate perfect


self.myObj = QGraphicsEllipseItem(QtCore.QRectF(0, 0, width-circle, high-circle), parent = None, scene = self.scene)Ç

Thanks

Lykurg
6th July 2010, 09:55
What's about using QGraphicsItem::setTransformOriginPoint():cool:

JohannesMunk
6th July 2010, 11:27
That indeed, simplifies the matter :->

Joh

pispipepe
28th July 2010, 20:05
i read documentation but i never had seen "setTransformOriginPoint" just i needed.
thanks.