showing icons - setPixmap problem
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):
Code:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
logoLabel
->setPixmap
(QPixmap(":/images/icon1.png"));
ui->layout->addWidget(logoLabel);
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
Re: showing icons - setPixmap problem
":/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.
Re: showing icons - setPixmap problem
Thank a lot! I've created resource file, and now it works fine!
best regards
Tomasz
Re: showing icons - setPixmap problem
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
Re: showing icons - setPixmap problem
just type the path without ":/" on the begining - then a graphics will be reading from files