PDA

View Full Version : QLabel and setPixmap causes flickering



roxton
29th August 2010, 19:36
Hello! I'm writing a simple wave editor. My current code of the waveform viewer is based on some steps:
1. Prepare the QPixmap with the portion of the waveform (according to the scrollbar position).
2. Use the generated pixmap with QLabel->setPixmap to show the picture.
3. This code is connected with the QScrollBar::valueChanged signal.
So I have the flickering on each valueChanged. The label quickly goes black, then my image is appear.
Is there a cure or another way to draw pixmap without a blinking? If you interesting, you can look at the source code at http://eko.git.sourceforge.net/git/gitweb.cgi?p=eko/eko;a=tree - the code of waveform redraw is in the document.cpp - CWaveEdit::draw_waveform function.

wysota
29th August 2010, 19:43
Your code is awfully slow as you are drawing on an image only to convert it to a pixmap. One thing to optimize is to draw immediately on a pixmap. Another is to redraw only this portion of the pixmap that actually needs redrawing. It would probably be a wise thing to have the whole wave pregenerated into a pixmap and only copy part of the rendering into another pixmap that will be set on the label (or simply use QScrollArea with the pregenerated pixmap set onto a label). This all should help but honestly your label shouldn't be going black regardless of the speed of your code. If it does, there is probably some logical error in the code causing a black pixmap to be created and rendered onto the label before the proper pixmap is generated.

roxton
30th August 2010, 10:26
I'm render just a visible part of the waveform to avoid the full sound peaks calculation. So I think that the rendering of the whole waveform is more time consuming and memory consuming too.
If I use the QPixmap directly, I get the image with some garbage/noise (partially overlapped the waveform).

Update: all fixed! I use QImage::Format_RGB32 now and all works fine :)

wysota
30th August 2010, 10:40
I'm render just a visible part of the waveform to avoid the full sound peaks calculation. So I think that the rendering of the whole waveform is more time consuming and memory consuming too.
It depends whether it is a common task to scroll the wave back and forth. You either calculate the same things once or multiple times.