How to create customized widget in glade project.

1. Create a new glade project, either Gnome or Gtk+.

2. In "Gtk+ Addtional" tab, click the "Custom Widget" button labeled with "C", and add this DUMMY widget into any container of a top-level window.

3. In "Properties" dialog, fill the "Name" field, and then fill the "Creation Function" field (e.g., create_gtksrcview), other arguments can be ignored.

4. Save the glade file, and DO NOT compile the glade to C/C++ source code.

5. Initialize the UI from glade file, and show the main window, as following:

ui = glade_xml_new("./", NULL, NULL);
main_wnd = glade_xml_get_widget (ui, "main_wnd");
gtk_widget_show (main_wnd);

6. Define the customized widget create function in C file, the function name must equal to the one you setup in glade file, and this function will be invoked automaticlly by libglade, and at last, you must SHOW the widget you created.

create_gtksrcview (gchar *widget_name, gchar *string1, gchar *string2, gint int1, gint int2)
GtkWidget *view;
GtkSourceBuffer *buffer;
... ...
view = gtk_source_view_new_with_buffer (buffer);
... ...
gtk_widget_show (view);
return view;

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

To submit your comment, click the image below where it asks you to...
Clickcha - The One-Click Captcha