GTK4 C set app icon

,

Hello,
I have another problem with my app .

I need to app assign my own icon.

I have read:

and according that I place my iccon into: ~/.spider4/hicolor/apps/48x48/oko_male.png
its size is 48x48 px and resolution 72x72 px/in (according gimp)

my code is:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>


using namespace std;

static void appActivate (GApplication *app, gpointer user_data)
{
    GtkIconTheme* icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
    gtk_icon_theme_add_search_path(icon_theme,"~/.spider4/");

    if(gtk_icon_theme_has_icon(icon_theme,"oko_male")!=1)
    {
        cout << "some problem with icon"<< endl;
    }

    gtk_window_set_default_icon_name("oko_male");

    GtkWidget *win = gtk_application_window_new (GTK_APPLICATION (app));
    gtk_window_set_title (GTK_WINDOW (win), "Your app");
    gtk_window_set_icon_name(GTK_WINDOW (win),"oko_male");

    GtkWidget  *vBox = gtk_box_new (GTK_ORIENTATION_VERTICAL,10);
    gtk_window_set_child (GTK_WINDOW (win), vBox);

    GtkWidget *labText;

    labText = gtk_label_new("pokus1");
    gtk_box_append (GTK_BOX (vBox), labText);

    labText = gtk_label_new("pokus2");
    gtk_box_append (GTK_BOX (vBox), labText);

    GtkWidget *btnBack = gtk_button_new_with_label("Close");
    gtk_box_append  (GTK_BOX (vBox), btnBack);
    g_signal_connect_swapped(GTK_BUTTON(btnBack), "clicked", G_CALLBACK(gtk_window_destroy), win);

    gtk_widget_show (win);
}


int main(int argc, char **argv)
{
    GtkApplication *app;
    app = gtk_application_new ("testing.app", G_APPLICATION_FLAGS_NONE);
    g_signal_connect (app, "activate", G_CALLBACK (appActivate), NULL);
    return g_application_run (G_APPLICATION (app), NULL, NULL);
    g_object_unref (app);

    return 0;
}

When I run my app I receive message
some problem with icon
and icon is not changed

I have also tried call command:
gtk-update-icon-cache -f -t ~/.spider4/

which answers me:
gtk-update-icon-cache: Cache file created successfully.
but also without any effect

All these tests I am dooing at Xubuntu 22.04

I hope that xubuntu allow it for gtk4 apps like for other apps:
obrazek

thank you for any advice.

I found solution! problem was in place of iccon! correct place is: /usr/local/share/icons/hicolor/48x48/apps/oko_male.png

be sure of folder order! I have found instructions with folder: /usr/local/share/icons/hicolor/apps/48x48/oko_male.png

but it not works.
command is not neccessary.

My program icon does not show up in gdm even though the icon file can be found in the path. The sourcetrail.appimage I use is not using desktop file and still shows the icon.

Still a lot of mystery

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