[PyKDE] Displaying an image

Matthew Singer matt at finaldraftbooks.com
Tue Aug 17 01:56:56 BST 2004


Thanks Jim,

This got me an image, but the color map is all wrong.  What else so I have
to do?


    q = QWidget()
    view = QLabel(q)
    pixmap = QPixmap()
    pixmap.load("myimage.jpg")
    view.resize(pixmap.size())
    q.resize(pixmap.size())
    view.setPixmap(pixmap)
    view.show()
    q.show()

-----Original Message-----
From: Jim Bublitz [mailto:jbublitz at nwinternet.com] 
Sent: Sunday, August 15, 2004 7:15 PM
To: pykde at mats.imk.fraunhofer.de
Cc: Torsten Marek; matt at finaldraftbooks.com
Subject: Re: [PyKDE] Displaying an image


On Sunday 15 August 2004 15:01, Torsten Marek wrote:
> > I need to embed a jpg file in a dialog.  As a test was just trying 
> > something
> > like:
> >
> >     view = QWidget()
> >     pixmap = QPixmap("myimage.jpg")
> >     view.resize(pixmap.size())
> >     p = QPainter(view)
> >     p.drawPixmap(0,0,pixmap)
> >     view.show()
> >
> > A window pops up, but it is empty.  What am I doing wrong?
>
> Maybe you need to call QPainter.end() before showing the widget? I'm 
> just guessing, because I cannot try out the code right now. If this 
> does not help, reading through the QPainter docs and copying the code 
> snippets might help.

Alternatively, make 'view' a QLabel instead of QWidget, since QLabel knows
how 
to display a pixmap (or look at the QLabel C++ code if you really need to 
draw it yourself)

Jim






More information about the PyQt mailing list