4

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"));
msrd0
  • 7,816
  • 9
  • 47
  • 82
user2302702
  • 95
  • 1
  • 7

1 Answers1

10

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

QPixmap(":/img/dog.png");
msrd0
  • 7,816
  • 9
  • 47
  • 82