GtkBuilder and "names"

I am trying to get the "names" of all GtkWidgets in a GtkBuilder object.

I managed to get all the objects from the builder through gtk_builder_get_objects() and save them in a GSList.

However, when I use gtk_widget_get_name() in gobjects (which I drop in GtkWidgets), I get common names like "GtkWindow" and "GtkButton" instead of "window1" or "button1" that appear in the meadow.

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

+6
source share
2 answers

The names given to the builder do not match the name GtkWidget . GtkBuilder maintains an internal hash table that has the name set in the GtkBuilder UI definitions from the file or line (from which the builder was added) and the associated object. It is used to retrieve objects when gtk_builder_get_object () called. Use the "name" property of GtkWidget . Set the "name" property in the GtkBuilder UI definitions to set the GtkWidget name, which can be obtained with gtk_widget_get_name() .
Hope this helps!

+3
source

I'm doing the same thing. I managed to get the id= lines from the .glade file using gtk_buildable_get_name() , as indicated here .

Note Prior to 2.20, GtkBuilder set the "name" property of the built widgets to the "id" attribute. In GTK + 2.20 or later, you should use gtk_buildable_get_name() instead of gtk_widget_get_name() to get the "id" or set the "name" property in your user interface definition.

+4
source

Source: https://habr.com/ru/post/902344/


All Articles