How to effectively scroll 1024x90000 image in a window?
Asked Answered
L

1

9

I have the following UI, where the sonogram (freq+time sound representation) is shown. So the image is not loaded from somewhere, it is drawn by QPainter while reading WAV file.

The UI

My current implementation is a single huge QImage object, where the image is drawn. And on paintEvent(), I draw part of the large QImage on the widget:

QPainter painter(this);
// (int, int, QImage*, int, int)
painter.drawImage(0, 0, *m_sonogram, 0, m_offset);

But, as i know, the QPixmap is optimized for displaying pixmaps on the screen, so should I convert the QImage to a QPixmap after the drawing of the sonogram is done?

Also, is it worth to keep large image as some kind of a linked list of separate QPixmap objects of smaller size and make paintEvent() smarter to operate on a list of smaller objects to avoid Qt's auto-cutting procedures and so on?

When my QImage is large enough, each paintEvent() consuming a lot of CPU.

All kinds of advices are welcome :)

Landwaiter answered 25/2, 2012 at 17:57 Comment(3)
Perhaps post something about machines you want this to run on. Using linked list could be smart depending on the target machines.Blatant
Maybe I'm wrong, but it seems you draw the entire image every paint event. You could paint only the portion of the image you're currently showing on the viewport. That's should keep CPU consuming constant.Menfolk
@Masci: See the "Automatic Clipping" note in the QPaintEvent docs: Qt does this automatically and you don't need to explicity copy any QPaintEvent clipping state to your QPainter.Hutto
H
1

Yes, in my limited experience of Qt app development, if you have a static image (or an infrequently updated image) it's well worth (for performance purposes) creating a QPixmap from it and keeping it around to use via QPainter::drawPixmap in your paintEvent handler.

However, I've never tried doing this with anything larger than about 4Kx4K images, so whether it will work for your enormous image or fall over horribly when you start to stress your graphics memory I couldn't say. I'd certainly try it out before considering adding a complicated tiling system.

Hutto answered 28/2, 2012 at 23:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.