开发者

GTK how to use gtk_builder_add_from_string()

开发者 https://www.devze.com 2023-01-24 10:31 出处:网络
I am new to Gtk and I am also using Glade to design a GUI. What is the necessary steps to show a GUI designed in glade by using gtk_builder_add_from_string() ?

I am new to Gtk and I am also using Glade to design a GUI.

What is the necessary steps to show a GUI designed in glade by using gtk_builder_add_from_string() ?

So far I loaded a .glade file into memory , ran g_type_ini开发者_运维技巧t() and I got myself a gtk_builder_new() struct that I pass to gtk_builder_add_from_string().

What do I need to do next to show the GUI and "talk" with the widgets?

(sorry for a possibly stupid question but me and google are not exactly friends today)


I always thought this was a very good tutorial: https://web.archive.org/web/20151230154736/http://www.micahcarrick.com/gtk-glade-tutorial-part-1.html


In general the steps are the following:

  1. Get the builder (you got it)
  2. Call gtk_builder_add_from_string. That string has to be created in the .glade file. You just have to convert the file into a C string.
  3. You can get the different graphical elements using gtk_builder_get_object(builder,"name"), where name is the name of some element. You usually have a top-level window in it.
  4. Call the show() method on all the widgets you recover from the builder. In particular, the top-level windows.

This will bring your application to life. Note that you also can connect signals and such. You can see an example here.

0

精彩评论

暂无评论...
验证码 换一张
取 消