"missing-image" icon?

After compiled a glib resource bundle with some PNG icons (inside “/icons” path), I tried unsuccessfully to check out both Gtk::Window::set_icon_name() and Gtk::Image::set_from_icon_name().

I wrote the following C++/Gtkmm 4.0 code (irrelevant parts removed)

	class Window
	:
		public Gtk::Window
	{
	public:

		Window()
		:
			refIconTheme (Gtk::IconTheme::create())
		{
			refIconTheme->add_resource_path ("/icons");
	
			for (auto & it : refIconTheme->get_icon_names())
				std::cout << it << std::endl;

			set_icon_name ("great-app-logo");
			image.set_from_icon_name ("great-app-logo");		
		}

	private:

		Gtk::Image image;
		Glib::RefPtr<Gtk::IconTheme> refIconTheme;
	};

When listing, “great-app-logo” appears among the IconTheme icons; and Gtk::Image::set_from_resource (“great-app-logo.png”) runs fine, but not the case of set_icon_name (“great-app-logo”) and image.set_from_icon_name (“great-app-logo”), which shows the “missing-image” icon.

What should be happens ?

https://developer.gnome.org/gtkmm/stable/classGtk_1_1IconTheme.html#accce53ab7a0b3f7b55e4e92e077da14d

Try adding the resource path to the icon theme in use rather than creating a new instance.

The following code, for me, it does not run, either…

The resource path is well registered but icons are not found by names.

	class Window
	:
		public Gtk::Window
	{
	public:

		Window()
		:
			refIconTheme (Gtk::IconTheme::get_for_display (get_display()))
		{
			refIconTheme->add_resource_path ("/icons");
	
			for (auto & it : refIconTheme->get_icon_names())
				std::cout << it << std::endl;

			set_icon_name ("great-app-logo");
			image.set_from_icon_name ("great-app-logo");		
		}

	private:

		Gtk::Image image;
		Glib::RefPtr<Gtk::IconTheme> refIconTheme;
	};

In order to use named icons you will need to follow the file system layout outlined in the icon theme specification, even in your GResources.

There are a few examples on the wiki that you can follow.

1 Like

In order to use named icons you will need to follow the file system layout outlined in the icon theme specification, even in your GResources.

It should still work though even if that’s not case, at least according to the docs anyway.

No, it really should not work unless you use an icon theme path.

If the docs say otherwise, then the docs need to be fixed. Please, file an issue asking for a clarification.

Will do when I get a chance.

The docs for 3 definitely need that removed then, not sure about 4 I’ll have a look later.

It did work in gtk3, so the most people bundling icons did that, but gtk4 removed that behaviour

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