Billy Pilgrim
Billy Pilgrim

Reputation: 1852

Newbie: Minimal program to display a PNG in a window

All,

I must have a fundamental neuron missing, but I cannot get a simple program to load a PNG file and display it in a window. I'm not sure if it is a QPixmap, a QPicture, or what. All of the samples in the QTCreator are a bit more than I need right now. Baby steps...

I can get the window to display, and the program doesn't barf when I try to load the PNG, but it never gets displayed.

If someone would post a simple program to load a PNG from a file and display it, it would greatly appreciated. (I know, asking a lot, but...).

Thanks!

:bp:

Upvotes: 0

Views: 308

Answers (1)

Julien-L
Julien-L

Reputation: 5416

this example is minimal: http://doc.trolltech.com/4.6/widgets-imageviewer.html

You will want to have a look at the function ImageViewer::open():

  1. Build a QImage object from a filename;
  2. Convert your QImage to a QPixmap with QPixmap::fromImage();
  3. Put your QPixmap in a QLabel with QLabel::setPixmap().

The QImage object will automatically chose an appropriate reader according to the format of the image it detects in step 1.

Upvotes: 1

Related Questions