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 :)

pavelkolodin
  • 2,859
  • 3
  • 31
  • 74
  • Perhaps post something about machines you want this to run on. Using linked list could be smart depending on the target machines. – EKS Feb 26 '12 at 16:42
  • 3
    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. – Masci Feb 28 '12 at 12:20
  • @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. – timday Feb 28 '12 at 23:19

1 Answers1

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.

timday
  • 24,582
  • 12
  • 83
  • 135