PDA

View Full Version : Transformations on QGraphicsItem



manojmka
28th November 2007, 10:52
Hi Guys,

I am working on GraphicsScene and GraphicsItem classes. I have multiple graphics items on one GraphicsScene and want to apply transformations on the same. The idea is that whenever user clicks on a graphicsItem, the item should appear selected with some images on all corners to rotate and scale the item. I implemented another item class for this purpose and made it the parent of selected item.
Now, as soon as the user clicks on corners of parent class, the item should be scaled and rotated.
Any idea, how to achieve that?

Regards,
Manoj

wysota
28th November 2007, 11:35
Use QGraphicsItem::scale and QGraphicsItem::rotate to transform the item. But I wouldn't use any additional items for the selected state. You should implement that in the item itself by changing its painting routine.

manojmka
28th November 2007, 11:54
But it means that I implement same paint functionality for every item class I display on the scene?

wysota
28th November 2007, 12:30
Yes. But you can embed that functionality in another class or function and reuse it for each object class you use.

manojmka
28th November 2007, 12:48
I think this is not possible without having a parent item for those items as all the functionality in mouse events and paint event will have to be implemented to scale, rotate and translate the items.

wysota
28th November 2007, 16:22
Trust me, it's possible. What do you need a parent item for? You can do the scaling, rotating, etc. in the view or the scene.

manojmka
30th November 2007, 04:58
Well, I think I am really confused here then. Is it possible for you to give me some sample code if you have?

Gopala Krishna
30th November 2007, 07:58
Try out the code mentioned in the blog
http://labs.trolltech.com/blogs/2006/12/15/interact-with-volatile-graphics-items/

manojmka
30th November 2007, 11:35
Hmmmm...

I have already tried it, the source code is not there.

wysota
30th November 2007, 11:58
What do you mean it's not there? Take a look at the implementation of the mouseMove event present there.

Gopala Krishna
30th November 2007, 13:25
Hmmmm...

I have already tried it, the source code is not there.

Yes , infact the source code tarball seems to be removed. I am attaching that for your reference, i hope Andreas doesn't mind. :)

@admin and bitto: How about making this a wiki article ?

wysota
30th November 2007, 13:32
Is there a point doubling what's already @ labs? Besides, there are no "discoveries" in the article :) Using scenePos() to calculate the origin is a natural thing to do ;)

Gopala Krishna
30th November 2007, 15:02
Is there a point doubling what's already @ labs? Besides, there are no "discoveries" in the article :) Using scenePos() to calculate the origin is a natural thing to do ;)

as you can see the articles/blogs are gradually lost and the new comers won't even know that somewhere some info is hidden in a great blog :(
So atleast a link in the wiki can be mentioned and also "the natural thing" isn't quite obvious for newbies :)

wysota
30th November 2007, 15:05
Feel free to make an article, as long as you don't violate any copyrights.

manojmka
3rd December 2007, 08:35
Now, in the example attached everything i.e. scaling, rotation is done in mouseMoveEvent function of interactive item. I want the same interactions to be performed on different items like pixmap, text or rectangle. The item which has current mouse focus or grabbed should also appear with special images on all corners.

Hope this makes the problem very clear this time?

wysota
3rd December 2007, 10:01
But we don't see the problem - just draw those "special images" in your item in its paint() routine based on its state (like selected/not selected).

manojmka
5th December 2007, 13:20
I think the problem was in my class design and it did not follow my all requirements. Anyways, I have now completely changed it and not using QGraphicsPixmapItem and QGraphicsTextItem. I have created my own pixmap and text item classes instead and inheriting them from my own GraphicsItem class.
Thank you very much for all the support and time.