PDA

View Full Version : showing icons - setPixmap problem



Tomasz
21st July 2010, 11:55
Hello!

I've got problem with showing icons. I've read code from program where icons were used (on buttons or just somewhere on window). I've wrote code (based on that program):




MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

logoLabel = new QLabel(this);
logoLabel->setPixmap(QPixmap(":/images/icon1.png"));
ui->layout->addWidget(logoLabel);

button = new QPushButton;
button->setIcon(QIcon(":/images/icon2.png"));
button->setIconSize(QSize(48, 48));
button->setFixedSize(150, 60);
ui->layout->addWidget(button);
}


but nothing shows. No icons (button is 'empty'). Images are in directory images/ where my source code is. What I'm doing wrong?

thanks in advance
best regards
Tomasz

Lykurg
21st July 2010, 12:28
":/foo" means that the image is in the Qt Resource System. Either give an absolute path, a correct relative path or the best: use the resource system. You will find a good explanation in the docs.

Tomasz
22nd July 2010, 10:07
Thank a lot! I've created resource file, and now it works fine!

best regards
Tomasz

Tomasz
18th November 2010, 08:37
I need to refresh that thread.
Since You've told me I'm using resource files. But sometimes I need to do to read graphics from files to put it for example into QLabel? With resource files it's easy, but sometimes I have a lot of files in one resource file, and binary is very big.

thanks in advance
best regards
Tomasz

produktdotestow
18th November 2010, 17:37
just type the path without ":/" on the begining - then a graphics will be reading from files