PDA

View Full Version : Zooming is too slow with QGraphicsView



learning_qt
3rd December 2008, 06:36
I load a big picture into QGraphicsView. Then I zoom it to 3x. But it is too slow. Are there some solutions to this problem.

I have to use QImage format in my case.

wysota
3rd December 2008, 10:15
Divide the image into smaller pieces.

learning_qt
3rd December 2008, 10:50
Thanks!

How can divide? Then I need to arrange those small images in a certain order. Could you please give some examples?

^NyAw^
3rd December 2008, 11:32
Hi,

Have you tried to use OpenGL on the viewport?

learning_qt
3rd December 2008, 12:03
No, I have not tried OpenGL for zooming in QGraphicsView.
When I run OpenGL examples with Ubuntu, I always have the problem:
Xlib: extension "GLX" missing on display ":0.0".
How can I resolve it?

^NyAw^
3rd December 2008, 12:32
Hi,

You have to install GLX for X Window. It is the openGL eXtension for X Window System.

learning_qt
3rd December 2008, 13:00
Thanks!

I have installed libgl1-mesa-glx and nvidia-glx. But the problems is still there. what else libs should i install?

^NyAw^
3rd December 2008, 15:16
Hi,

You have installed GLX but I think that you don't have X Window configured to use it. I really don't know how to activate it but you can search it on the web.

wysota
3rd December 2008, 23:56
Thanks!

How can divide? Then I need to arrange those small images in a certain order. Could you please give some examples?

Yes, you then need to arrange items but this is trivial so it should take you no more than 2 minutes to do it - load your image and create items from it where each item contains a 200x200 block of pixels, then set position of the images according to their offsets from the top left corner of the image.

You experience slowdowns because zooming causes your image to be scaled while being painted and because the image is big, it takes time. Furthermore as you zoom in closer and closer, regions of the image are moved out of the viewport but as the image is still one big item, the whole item (hence the whole image) has to be repainted. Dividing into tiles yields two benefits - items scale faster and there are less items to draw as those that move out of the viewport are ignored while updating the view.



Hi,

Have you tried to use OpenGL on the viewport?

This won't change much.

Edit:
Here is something to play with. If you compile it with OpenGL support (qmake QT+=opengl) it will use the OpenGL viewport. Run it without parameters to see the usage help. In general it gives quite nice results for me, the scrolling is smooth while the image is zoomed in. I tested it using images roughly 2000x2000 in size but for bigger images the gain should be even bigger (at the expense of memory usage).

learning_qt
4th December 2008, 08:35
Thanks!

But there is still one problem. When I zoom out, there are always white lines among tiles. I suppose those areas are not covered.

How can we resolve this problem?

wysota
4th December 2008, 09:23
You have to implement your own pixmap item. I guess the effect is caused by how QRect works or rounding problems. Providing your own proper implementation of a pixmap item should fix the problem. At worst you can use a bigger overlap between items (I used 1x1 overlap which already helped, if you use 2x2 it should be much better).