[PyKDE] QLabel flashes on setPixmap

mernst at tricity.wsu.edu mernst at tricity.wsu.edu
Sun Apr 18 09:09:01 BST 2004


I'm building an application where a cutaway view of the human body has
various organ systems coded by color. This is a single raster image,
displayed using a QLabel with a pixmap. I want to perform simple
operations: changing colors of the organs when the user selects a
different data set, and scaling the image when the size of the main
application window changes. I retain a high-resolution QImage as
self.masterImage, scaling it when the main window size changes. I maintain
a lower-resolution QImage as well because the more common operation will
be changing the image palette and converting it to a pixmap, and I don't
want the performance overhead of rescaling the image (from the
high-resolution master) every time the palette changes.

So far things work pretty satisfactorily (I haven't yet added the palette
changing), but the QLabel flashes in a distracting fashion whenever I call
setPixmap. Going to a double-buffered QCanvas seems like overkill for my
problem; I really only want to display/update this single graphic. How
would I go about eliminating the flashing? I've read a bit about
eliminating flashing in custom widgets with double buffering, but this is
a stock Qt widget and I was surprised that updating its pixmap was so
visually jarring.

def slotUpdateImage(self):
        x, y = self.masterImage.width(), self.masterImage.height()
        if not hasattr(self, 'currentImage'):
            self.scaledImage = self.masterImage.scale(x *
(float(self.controlframe.height()) / y),
self.controlframe.height())
            self.currentImage = QPixmap()
        elif self.controlframe.height() != self.oldHeight:
                self.scaledImage = self.masterImage.scale(x *
(float(self.controlframe.height()) / y),
self.controlframe.height())
                self.oldHeight = self.controlframe.height()

        self.currentImage.convertFromImage(self.scaledImage)
        self.skellabel.setPixmap(self.currentImage)




More information about the PyQt mailing list