Question

I'm working on a project that has 40 checkable push buttons in a group and I want the icon of one button to change depending on a value I define. I'm not creating a new pushbutton, just changing the icon of the current one. So I'm testing it by trying to change one button's icon.

Here is my current code:

QPixmap b1d0(":/textures/blocks/textures/blocks/stone.png");

QIcon ButtonIcon(b1d0);
ui->slot_0->setIcon(ButtonIcon);
ui->slot_0->setIconSize(b1d0.rect().size());

The resource path was copied directly from my resource file so it is correct, I've messed with it like crazy but no change so...

slot_0 is my pushButton.

What did I do wrong? Or better yet, am I even allowed to change the icon of an existing pushButton?

Thanks for your time :)

Was it helpful?

Solution

If you are on Windows using MSVC as your compiler, and want to use Qt's resource system, you will need to add

Q_INIT_RESOURCE(res)

to the beginning of main(), where res is the name of your .qrc file without the ".qrc".

To get a full view of this, look at this gist:

https://gist.github.com/alexreinking/5992821

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top