[PyKDE] QPixmap to QWidget

Aurélien Gâteau aurelien at dental-on-line.fr
Fri Nov 28 17:41:01 GMT 2003


Le Vendredi 28 Novembre 2003 12:56, Tom Badran a écrit :
> I have a QPixmap object that i use for image data, and a QWidget object i
> wish to draw too. The qwidget has the same minimum size as the size of the
> QPixmap. Whats the best way of copying the QPixmap data to the QWidget data
> so that it is drawn on screen?

The simplest way is to reimplement paintEvent() like this:

def paintEvent(self, event):
  painter=QPainter(self)
  painter.drawPixmap(0, 0, myPixmap)


It's also useful to override the __init__() method, in order to avoid flicker:

def __init__(self, parent, name):
  QWidget.__init__(self, parent, name,
    Qt.WStyle_Customize | Qt.WRepaintNoErase | Qt.WResizeNoErase)


You could also use a QLabel instead of a QWidget and simply call 
QLabel.setPixmap(myPixmap) :-)

Hope this helps,
  Aurélien




More information about the PyQt mailing list