Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. COActually Autopulated's suggestion of subclassing QGraphicsItem and overloading paint worked out really well. It means that I can paste empty QGraphicsItem's onto the scene. This shouldn't take up much memory. The paint method of a QGraphicsItem get called only when it is visible inside the view. So I've implemented it such that your actual image data only gets loaded into the object when it is visible in the view. So loading tiles is pretty much taken care off. Now the only problem remain in unloading unused tiles.
      singulars
    2. COAfter considering several approaches I think I'm going to use a Queue approach to tiles. I'll maintain a queue of constant size that takes in a new tiles and deletes old tiles (FIFO). This should be much better than using a timer. What do you think?
      singulars
    3. COAnd I've considered the zooming problem early on. What I've planned to do is construct tiles of several zoom levels(Like tile level 0 -> 100% level 1->50% etc). As long as the user is zooming between 50-100% zoom I'll use the setScale fucntion in QGraphicsView (Another advantage of using QGraphicsView over QAbstractScrollArea). Once the user goes into the 25-50% zoom level a new set of tiles are loaded (level 1 tiles) and the scale is set back to 1. In short pyramiding should solve this. Also overriding paint in QGraphicsItem allows me to seamlessly integrate pyramided-zooming
      singulars
 

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