Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using custom widgets with glade / Gtkbuilder

I'm developing an application with Gtk and Glade. My impression is that it's common practice to create a subclass of GtkWindow for your main window, but I'm stuck on how I would construct my subclass from a GtkBuilder definition. Does anyone know how?

like image 979
Masterofpsi Avatar asked Jun 09 '10 00:06

Masterofpsi


1 Answers

Subclassing GtkWindow is more common in GTK's various language bindings than it is in plain C. You didn't mention which language you were using.

That said, the way I subclass GtkWindow in C is to create the contents of the window in Glade, but not the window itself. In Glade 3 (IIRC) you can right-click on a widget in the palette and choose "Add widget as toplevel" to place a non-toplevel widget without a container.

Then write code for your subclass of GtkWindow, let's call it MyAppWindow. I won't go into that in this answer since there are plenty of examples in the GObject documentation. In the init function (my_app_window_init()) load the Glade file, use gtk_builder_get_object() to get a pointer to the outermost widget in the Glade file, and use gtk_container_add() to add it to the window you are constructing. Then use gtk_builder_connect_signals() as you normally would.

You have to set all the window's properties manually this way, since you can't do it in Glade, but other than that I've found it works quite well.

like image 138
ptomato Avatar answered Sep 28 '22 13:09

ptomato