Reputation: 323
How can I get the file name of the image used in a GtkImage widget?
I have a GtkImage widget that displays different images. I want to be able to click on the GtkImage, determine which image has been clicked i.e. get the file name, then display a larger version.
Thanks,
Upvotes: 1
Views: 529
Reputation: 11395
You can get the value of "file"
property of GtkImage
using g_object_get_property
. Something on these lines:
GValue value = {0,};
/* If you have glib version 2.30 or higher use:
* GValue value = G_VALUE_INIT;
*/
g_value_init (&value, G_TYPE_STRING);
/* Assuming image is a valid GtkImage */
g_object_get_property(G_OBJECT(image), "file", &value);
printf("\n Filename = %s\n", g_value_get_string(&value));
Side note: To make use of the Glib
's type system, g_type_init()
should have been called. g_type_init()
is called internally as a consequence of Gtk initialization through gtk_init
.
Hope this helps!
Upvotes: 2