Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Although an answer has already been chosen, I'd like to express my opinion.</p> <p>I don't like the selected answer, especially because of that usage of timers. A timer to unload the pixmaps? Say that the user actually wants to take a good look at the image, and after a couple of seconds - bam, the image is unloaded, he will have to do something in order the image to reappear. Or may be you will put another timer, that loads the pixmaps after another couple of seconds? Or you will check among your thousand of items if they are visible? Not only is this very very irritating and wrong, but that means that your program will be using resources all the time. Say the user minimizes you program and plays a movie, he will wonder why on earth my movie is freezing every couple of seconds...</p> <p>Well, if I misunderstood the proposed idea of using timers, execuse me.</p> <p>Actually the idea that mmutz suggested is better. It reminded me of the <a href="http://doc.trolltech.com/4.7-snapshot/threads-mandelbrot.html" rel="noreferrer">Mandelbrot example</a>. Take a look at it. Instead of calculating what to draw you can rewrite this part to loading that part of the image that you need to show.</p> <p>In conclusion I will propose another solution using QGraphicsView in a much simpler way:</p> <p>1) check the size of the image without loading the image (use QImageReader)</p> <p>2) make your scene's size equal to that of the image</p> <p>3) instead of using pixmap items reimplement the DrawBackground() function. One of the parameters will give you the new exposed rectangle - meaning that if the user scrolls just a little bit, you will load and draw only this new part(to load only part of an image use setClipRect() and then read() methods of the QImageReader class). If there are some transformations you can get them from the other parameter(which is QPainter) and apply them to the image before you draw it.</p> <p>In my opinion the best solution will be to combine my solution with the threading shown in the <a href="http://doc.trolltech.com/4.7-snapshot/threads-mandelbrot.html" rel="noreferrer">Mandelbrot example</a>.</p> <p>The only problem that I can think of now is if the user zooms out with a big scale factor. Then you will need a lot of resources for some time to load and scale a huge image. Well I see now that there is some function of the QImageReader that I haven't tried yet - setScaledSize(), which maybe do just what we need - if you set a scale size and then load the image maybe it won't load first the entire image – try it. Another way is just to limit the scale factor, a thing that you should do anyway if you stick to the method with the pixmap items.</p> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload