PDA

View Full Version : Scaling QGraphicsPixmapItem



johnsoga
6th May 2009, 03:51
I am trying to create a multitouch gametable application. I have been trying to use a QGraphicsScene with a QGraphicsView for the gametable. I will be allowing users to add maps and create maps. What is the best way to add QGraphicsPixmapItems and allow users to scale and rotate the image without affecting performance. I have noticed that if I just apply a transformation matrix to the QGraphicsPixmapItem the rendering of the image takes a really long time. I have tried adjusting the cache mode but it doesn't allow me to adjust the transformation matrix.

Does anyone have a better idea for transforming pixmaps?

aamer4yu
6th May 2009, 05:31
Cant answer your question, but probably I have a question for you...
How do you use multi touch ? am curious abt its implementation..

johnsoga
6th May 2009, 15:19
I haven't got too far with the implementation of the multitouch. I am using the TUIO library from tuio.org which connects over udp to any multitouch server that supports the TUIO protocol. The TUIO protocol sends messages for when a cursor is created, moved, and then removed and it also support fiducial markers. Right now I am trying to create a simple app similar to the picture apps you see demonstrated that allows you to moved, rotate and resize images.

johnsoga
6th May 2009, 15:49
I should have posted the code I am using.



QGraphicsScene scene;
scene.setSceneRect(0,0,5000,5000)

QGraphicsPixmapItem testImage(QPixmap("./MOATHOUSE-FINAL.jpg"));
scene.addItem(&testImage);
testImage.scale(.5,.5);

QGraphicsView view(&scene);
view.showMaximized();
view.setBackgroundBrush(Qt::black);


When I scroll the view to where the image is located scrolling becomes very choppy. I have tried both


testImage.setCacheMode(QGraphicsItem::ItemCoordina teCache,QSize((testImage.boundingRect().width(),te stImage.boundingRect().height()));

and


testImage.setCacheMode(QGraphicsItem::DeviceCoordi nateCache);


Setting the cache mode works until I change the scale again and then scrolling the view is slow again when the pixmap is displayed.

wysota
6th May 2009, 21:20
How big is the image?

johnsoga
7th May 2009, 15:46
My image is 4000x3800

wysota
7th May 2009, 15:51
Don't expect miracles then. Scaling such an image takes time and this has to be done every time the transformation of your item changes. You can improve performance by cutting the image into smaller pieces and composing them into your large picture.

johnsoga
7th May 2009, 16:19
You can improve performance by cutting the image into smaller pieces and composing them into your large picture.

That is the next solution I was going to try. Do you know of any example programs that do that?

wysota
7th May 2009, 16:31
That is the next solution I was going to try. Do you know of any example programs that do that?

As far as I remember there is an example implementation of mine somewhere in this forum but it might be hard to find.

johnsoga
7th May 2009, 17:04
Okay, I will look around the forums. Thanks for the help