PDA

View Full Version : loading QPixmap doesn't work



dieter
20th November 2011, 10:40
MainPlayerBoard::MainPlayerBoard(QString naam, short count, QWidget *parent):
QMainWindow(parent),
ui(new Ui::MainPlayerBoard)
{
ui->setupUi(this);
QImage eerste;
eerste.load(":/image.gif");
ui->tile1->pixmap();
ui->tile1->setPixmap(QPixmap::fromImage(eerste));
ui->tile1->show();
MainPlayerBoard::setWindowTitle(naam);
m_count = count;
}


I first tried to load the pictures from a QVector<QPixmap*> which didn't work.
Then I tried to load them from a QPixmap, didn't work either...
after a while I tried this...
But the problem remains, the QPixmap on my screen does not show up...
Please help me out

Oleg
20th November 2011, 15:08
What is 'tile1'? I assume it should be QLabel in you UI. The following code is enough to show pixmap:


ui->pixmapLabel->setPixmap(QPixmap::fromImage(QImage(":/image.jpg")));

ChrisW67
20th November 2011, 23:07
MainPlayerBoard::MainPlayerBoard(QString naam, short count, QWidget *parent):
QMainWindow(parent),
ui(new Ui::MainPlayerBoard)
{
ui->setupUi(this);
QImage eerste;
eerste.load(":/image.gif");
ui->tile1->pixmap();
ui->tile1->setPixmap(QPixmap::fromImage(eerste));
ui->tile1->show();
MainPlayerBoard::setWindowTitle(naam);
m_count = count;
}


Line 7: Have you checked the return value from QImage::load()? Do you have a GIF image format plugin built and/or deployed?
Line 8 is pointless: I don't know what you are trying to achieve here, but you ignore the return value anyway.
Line 10 is pointless: The label (I assume tile1 is a label) will be shown by default when its parent is shown.

You should be able to construct a QPixmap directly from a GIF or PNG file without an intermediate QImage.