How to add custom icons to GResources?

This is my GitHub repo with the app.

How to add custom SVG icons to GResource to embed them to the app?

I tried to write this in src/lrcmake.gresource.xml file, but all icons are replaced by icon-missing
I store icons sources files in src/gtk/icons

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/com/github/dzheremi/lrcmake">
    <file preprocess="xml-stripblanks">gtk/window.ui</file>
    <file preprocess="xml-stripblanks">gtk/components/noDirSelectedGreeting.ui</file>
    <file preprocess="xml-stripblanks">gtk/components/songCard.ui</file>
    <file preprocess="xml-stripblanks">gtk/components/fileDetails.ui</file>
    <file preprocess="xml-stripblanks">gtk/components/syncLine.ui</file>
    <file alias="style.css">gtk/css/style.css</file>
  </gresource>
  <gresource prefix="/com/github/dzheremi/lrcmake">
    <file alias="publish-symbolic.svg">gtk/icons/share-symbolic.svg</file>
    <file alias="lyrics-symbolic.svg">gtk/icons/lyrics-symbolic.svg</file>
    <file alias="dir-open-symbolic.svg">gtk/icons/folder-open-symbolic.svg</file>
  </gresource>
</gresources>

GTK will look up icons in your GResource in the path {app-id-path}/icons/{size}/{context}/ (check this for more info: Themed Icons - GNOME Developer Documentation).

In your case it will be /com/github/dzheremi/lrcmake/icons/scalable/actions/ for all your icons.

1 Like

I have to make a remark. To implement the icons, this needs to be added to code:

theme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default())
theme.add_resource_path("/my/resources/icons")

This is only applicable if you’re not using Gtk.Application or derivatives like Adw.Application.

I wrote this for people like me, who is browsing across the Internet in searching of the answer for this question.

Thanks for your help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.