QToolBar Icons Not Showing
-
Hi,
I wrote a small C++ app using Qt Creator with my MacBook Pro. I created a QToolBar and put a couple Actions with Icons on the toolbar. The icons show in QT Creator, but when I run my program, the icons don't appear. The icons are in my resources.qrc file. I checked this file and even edited it to put the full path for one of the icons in it. That didn't make it appear either at runtime.So bottomline:
The QToolBar icons do not appear at runtime.
Any help or suggest would be greatly appreciated. I am stuck!
Thanks,
Zeke -
I solved this by loading the icons into the actions using an absolute path. I know it isn't pretty, portable, or standard, but it works for me on my computer. The only place this app will ever be used.
QString openIcon = "absolute path to my icon image"; ui->actionOpen->setIcon(QIcon(openIcon));
-
Hi and welcome to devnet,
Do you mean they do not appear when running your application with Qt Creator or when outside ?
Can you share the relevant code ?
Version of Qt ?
Version of macOS ? -
Hi SGaist,
I ran the app within Qt Creator and also standalone. Same results. I am using Qt Creator 15.0.1 and Qt 6.10.0. MACOS Sequoia 15.3.2. I uploaded a section of mainwindow.ui, resources.qrc, and a screenshot of my project directory. Thanks for your help!Here is my mainwindow.ui code:
<widget class="QToolBar" name="toolBar"> <property name="windowTitle"> <string>toolBar</string> </property> <attribute name="toolBarArea"> <enum>TopToolBarArea</enum> </attribute> <attribute name="toolBarBreak"> <bool>false</bool> </attribute> <addaction name="actionAbout_RSR"/> <addaction name="actionOpen"/> </widget> <action name="actionAbout_RSR"> <property name="icon"> <iconset resource="resources.qrc"> <normaloff>:/images/ToolbarInfo.icns</normaloff>:/images/ToolbarInfo.icns</iconset> </property> <property name="text"> <string>About RSR</string> </property> <property name="iconVisibleInMenu"> <bool>true</bool> </property> <property name="shortcutVisibleInContextMenu"> <bool>true</bool> </property> </action> <action name="actionAbout_Qt"> <property name="text"> <string>About Qt</string> </property> </action> <action name="actionOpen"> <property name="icon"> <iconset resource="resources.qrc"> <normaloff>:/images/PicturesFolderIcon.icns</normaloff>:/images/PicturesFolderIcon.icns</iconset> </property> <property name="text"> <string>Open...</string> </property> </action>
And here is my resources.qrc code:
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionAbout_RSR"/>
<addaction name="actionOpen"/>
</widget>
<action name="actionAbout_RSR">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/images/ToolbarInfo.icns</normaloff>:/images/ToolbarInfo.icns</iconset>
</property>
<property name="text">
<string>About RSR</string>
</property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
<property name="shortcutVisibleInContextMenu">
<bool>true</bool>
</property>
</action>
<action name="actionAbout_Qt">
<property name="text">
<string>About Qt</string>
</property>
</action>
<action name="actionOpen">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/images/PicturesFolderIcon.icns</normaloff>:/images/PicturesFolderIcon.icns</iconset>
</property>
<property name="text">
<string>Open...</string>
</property>
</action>
<RCC>
<qresource prefix="/images">
<file>Disney.png</file>
<file>ChrisAndJil.jpg</file>
<file>wildflowers2.jpg</file>
<file>camera.jpg</file>
<file>family-icon.jpg</file>
<file>snoopy.png</file>
<file>greenUp.png</file>
<file>ToolbarInfo.icns</file>
<file>PicturesFolderIcon.icns</file>
</qresource>
</RCC> -
When you deploy your application (with windeployqt, hopefully) make sure that the icons plugin is properly deployed (qico.dll)
-
-
I solved this by loading the icons into the actions using an absolute path. I know it isn't pretty, portable, or standard, but it works for me on my computer. The only place this app will ever be used.
QString openIcon = "absolute path to my icon image"; ui->actionOpen->setIcon(QIcon(openIcon));
-
1/6