c++user-interfaceiconstoolbarqt5.3

Adding an icon to a toolbar in Qt 5.3


I'm working on a project using Qt 5.3 and C++ 11.

I've inherited a semi-large code base and have never worked with Qt before, so a lot of the coding I'm doing for this is by modifying some of the earlier code for my purposes.

I'm currently tasked with adding some icons to a toolbar. My teammates managed to get the icons to appear on a Linux build, but it won't appear on OS X 10.10.

Currently, my .qrc looks like this

<RCC>
  <qresource prefix="/icons/tango">
    <file alias="index.theme">icons/tango/index.theme</file>
    // here are some currently working icons
    // Below are the icons I'd like to add
    <file alias="disk.png">icons/tango/led_icons/disk.png</file>
    <file alias="folder.png">icons/tango/led_icons/folder.png</file>
    <file alias="grid.png">icons/tango/led_icons/grid.png</file>
    <file alias="page.png">icons/tango/led_icons/page.png</file>
    <file alias="shape_flip_vertical.png">icons/tango/led_icons/shape_flip_vertical.png</file>
  </qresource>
</RCC>

and I set the icons in the following way

ui->actionV->setIcon(QIcon::fromTheme(":/icons/tango/folder.png"));
ui->actionW->setIcon(QIcon::fromTheme(":/icons/tango/disk.png"));
ui->actionX->setIcon(QIcon::fromTheme(":/icons/tango/shape_flip_vertical.png"));
ui->actionY->setIcon(QIcon::fromTheme(":/icons/tango/page.png"));
ui->actionZ->setIcon(QIcon::fromTheme(":/icons/tango/grid.png"));

For some reason, upon building I don't see what I'd expect.

Can anyone let me know what I'm doing wrong? I certainly don't think there's a bug with Qt, I think I'm just overlooking some minor detail.


Solution

  • I find the path of your file alias and the path you are using to set your icon to be different. It should be like: ui->actionV->setIcon(QIcon::fromTheme(":/icons/tango/led_icons/folder.png"));

    You are missing led_icons in your path.

    I guess this should work.