Question

I've been trying to get the "names" of all GtkWidgets in a GtkBuilder object.

I've managed to get all objects from the builder object via gtk_builder_get_objects() and store them in a GSList.

However, when I use gtk_widget_get_name() on the gobjects (which i cast to GtkWidgets), I get generic names such as "GtkWindow" and "GtkButton" instead of "window1" or "button1" that are displayed in glade.

Any help would be extremely appreciated and would make this programmer very happy.

Was it helpful?

Solution

The names set for the builder are not the same as name of the GtkWidget. GtkBuilder maintains an internal hash table which has the name set in GtkBuilder UI definitions from the file or string (from which builder was added) and associated object. It is used to retrieve the objects when gtk_builder_get_object () is called. Make use of the "name" property of GtkWidget. Set "name" property in the GtkBuilder UI definitions to set the name of the GtkWidget which can be retrieved using gtk_widget_get_name().
Hope this helps!

OTHER TIPS

I am doing the exact same thing. I was able to get the id= strings from the .glade file using gtk_buildable_get_name() as specified here.

Note: Prior to 2.20, GtkBuilder was setting the "name" property of constructed widgets to the "id" attribute. In GTK+ 2.20 or newer, you have to use gtk_buildable_get_name() instead of gtk_widget_get_name() to obtain the "id", or set the "name" property in your UI definition.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top