Important: Please read the Qt Code of Conduct -

How to handle huge images with level-of-detail in QGraphicsView?

  • Hi all,

    First a tiny bit of background. I am working with huge tiled images which are stored in a multi-resolution pyramid (image sizes of around 50000 x 50000 pixels). The lowest level of the pyramid contains the full version of the image, and each subsequent level a 2x downsampled version. Images are stored with 512x512 tiles.

    My idea was to subclass QGraphicsItem and reimplement the paint function to only visualize the part of the image that is in view and use the level-of-detail to determine which level to load. However, I am running into some problems.

    I implemented boudingRect to return the full image size (50000 x 50000) and my idea was that when I put such an item into a scene, then the level-of-detail would be QGraphicsView size / QGraphicsItem size. However, the levelOfDetail passed to the paint function is simply 1, forcing the loader to load the full resolution image (which of course does not work). I looked at the 40000 chips example, which uses the WorldTransform to determine the correct scale. This does work for loading the right level and data, however, when I then draw the obtained pixmap, it is much to small (as the painter also takes the world matrix into account). Does anyone have any ideas on how to best handle this? Thanks!

  • If you already have an image pyramid, you may want to look at using a QWebView (an embedded WebKit browser) and "Open Seadragon" to embed "deep zoom" functions in your app. You'll get blazing fast viewing of any sized image without having to worry about "how" to do it.

  • Thanks for answering. I am familiar with OpenSeadragon, however, we need users to be able to interact with the image from the application (e.g. making annotations). As such, we prefer a Qt-based solution

  • That's the beauty of QtWebKitBridge - you can really have a hybrid solution. I had to solve this very problem already and to me, the Open Seadragon "deep zoom viewer" was so amazingly fast and fluid for zipping around very large image pyramids that it made no sense to try to reinvent that, even with all the high quality features of Qt.

    Using a javascript framework like fabric.js you can implement nice annotation tools over the seadragon layer within the HTML environment. Data sharing is very straight-forward with the WebKitBridge so you can serialize your annotations using JSON or XML and embed any other kind of interactions between the Qt and WebView layers.

  • Thanks again for answering, well, we have a lot of the functionality that is in OpenSeadragon already in place (interfacing with the image, caching of tiles, prefetching). I would still prefer a QGraphicsView based solution, as this is just more straightforward to implement. Additionally, I have the feeling that it should be that hard to implement using a QGraphicsView.

Log in to reply