Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QPixmap only works with absolute Path

Tags:

c++

qt

qpixmap

I am trying to set icons for my QPushButtons. I was only able to do so by putting the full path into the QPixmap constructor.

Something like this works:

m_button->setIcon(QPixmap("C:/Users/Desktop/project/img/pic.png"));

So I think the problem does not come from the resource files. However, putting the image into my root directory does not display anything.

So this didn't work:

m_button->setIcon(QPixmap("./dog.png"));

I initially wanted to create an image folder inside my project but that didn't work either.

m_button->setIcon(QPixmap("./img/dog.png"));
like image 734
user2302702 Avatar asked Dec 25 '22 03:12

user2302702


1 Answers

You should add Qt-Resource-File to your application, add the image into it, and the call it like this:

QPixmap(":/img/dog.png");
like image 94
msrd0 Avatar answered Jan 11 '23 08:01

msrd0