Previous Next

The Widgets in More Detail

What follows is a listing of the more commonly used widgets, and some of the gtk functions that are used with their elements. None of these have any of the function parameters listed, and not all the functions for each widget are listed. For these please refer to the pages linked to in the library section of this tutorial.

Note that the following is NOT an exhaustive list of widgets. There are widgets available with different libraries that aren't included in Glade. There are also a few Gtk+ widgets which are so self explantory (ie vertical and horizonal separators), that they weren't included here.

Gtk+ Basic Widgets
ImageNamePurposeFunctions and Considerations
gtk window iconWindow Basic Gtk WindowNo specific functions coder needs to take care of, but if this is the main window you do need to attach a gtk_exit() to the delete_event signal (ie when they click the x in the top righthand corner).
Gtk Dialog WindowDialog WIndowcreates a basic dialog box/windowThere are no specific functions for this. You'll have to add the buttons to the buttonbar and whatever else you want.
Gtk File Selection File Selection Dialogcreates a standardized file selection dialog window The internal workings are handled by the widget. You'll need to connect signals to the buttons (ie the clicked signal), as well as grab the selection.
Gtk Color Selection Dialog Color Selection DialogA dialog window for selecting colors This creates a standardized color selection dialog box/window. You'll have to make all the buttons work, and grab the selection with gtk_color_selection_get_color().
Gtk Font Selection Dialog Font Selection DialogA dialog window for selecting fonts This is a standardized dialog box/window, for selecting fonts. You'll need to grab the selection and set up the buttons, as usual. Use gtk_get_font_selection_dialog_get_font() for this. There are other functions for getting the font's name and so on. See the GTK+ Reference Manual listed in the help section of this tutorial.
gtk menubarMenu Bar Creates a Menu BarYou will have to create handlers for all the activate signals for the dropdown menus. There is a menu editor in Glade to help you do this, and see the menu editor section of this tutorial for a guide.
gtk toolbarToolbarCreates a Tool BarYou will have to attach handlers to the buttons (clicked signal usually). Also you'll have to supply icons (or use the standard ones) and names for the buttons. Do this in the properties window for each button.
gtk labelLabelcreates a label widgetThere are generally no signals here. This allows you to put labels into your creations.
gtk entry widgetText Entryallows entry of a single line of text use gtk_entry_set_text(), gtk_editable_get_chars(), gtk_entry_set_editable() and other functions to manipulate the text in this single line box. These are commonly used upon activate and changed signals. With the changed signal, set a flag, and grab the entry data later (ie when an ok button is clicked).
gtk Combo BoxComboBoxcreates a text entry box with dropdown entries Use this box, or the Gnome entry, to create dropdown lists of entries. Gnome entry manages this list for you, with ComboBox you'll have to manage it yourself. Use the text entry functions with this, as well as specific combobox ones: gtk_combo_set_value_in_list() etc.
gtk text box Text View A multi-line text editor This widget has changed substantially from Gtk+ 1.*. To use it you create a GtkTextBuffer, which is the text being edited, and show it in the GtkTextView. In a very simple application you get the buffer with gtk_text_view_get_buffer(), and set it with gtk_text_view_set_buffer(). The buffer itself emits signals, such as changed, insert_text etc. The view also emits signals such as copy_clipboard, move_focus, etc.
Gtk ButtonButton A basic buttonWith this, and all buttons, the signal most commonly used is the clicked signal, although you can also use enter, leave, pressed, released, etc. There are no particular functions to use to get data here, but often times you will want the button to eventually destroy its parent window. Use gtk_widget_destroy() for this.
Gtk Toggle ButtonToggle ButtonA basic toggle buttonThis button is meant for use with variables/entities that have two states, on/off, 0/1 etc. It has a special signal, toggled, as well as all the normal button signals.
Gtk Check ButtonCheck ButtonA check button (toggle with a label)This is a toggle button, so again it has two states (on/off etc). This button also has a label, making it a labeled toggle button. You can use the toggled signal with it.
Gtk Radio Button Radio ButtonA radio toggle buttonThis is a special kind of check button. Radio buttons are grouped together, and when one is picked all the others turn 'off', or are deselected. This allows the coder to let the user select one from a list of however many items. The signal here is toggled, of course. In the Properties window you will have to set the 'group' of the radio button, as well as its label.
Gtk Option MenuOption Menucreates a menu from which a user can choose one option Common signals are clicked, enter, leave, pressed, etc. Functions include gtk_option_menu_get_menu(), gtk_option_menu_set_menu(), etc. There is an example of how to link a handler to this widget later in this tutorial.
Gtk Spin ButtonSpin Button A button that increments a counterThis is a useful way to get numbers from a user, numbers that are within a set range, and are always numeric (if you set the numeric value to TRUE in the properties window). You can also set the range, the increment, and the start value. The changed and activate signals can be used to retrieve the data within the spinbutton entry. Use gtk_spin_button_get_value_as_float(), or gtk_spin_button_get_value_as_int(), for example. (Remember to set a flag with the changed signal and retrieve the data later (ie when an ok button is clicked)).
Gtk Status BarStatus Bar A place to put status messagesThis bar is usually found at the bottom of a window, and is a place that indicates program actions. For instance, if the user clicks on a button to save a file, you can write 'File Saved' here. Use the gtk_statusbar_push(), gtk_statusbar_pop() functions, among others, with this.
Gtk List or Tree View List or Tree View a widget for displaying both trees and lists This is a new widget for Gtk+ 2.0, replacing the ctree, clist, list and tree widgets that were previously used. It is a bit complicated in theory, but simple in practice. See the API for more information, but basically you create a list or tree model, and view it in the list/tree view.
Gtk Image Gtk Image shows an image This is a no window widget, it doesn't receive events, it is simply for displaying an image/animation/whatever.
Gtk Drawing Area Drawing Area A place to create custom widgets Use this widget to create custom widgets, to draw things (like graphs), etc.
 
Gtk Containers
gtk handle boxHandle Boxcreates a container box which can be moved by the handle No signals here, they are handled internally with the container box. The box is one of those 'rip away' boxes which you can use to create menus that the user can move around the screen as she wishes.
Horizontal Box WidgetHorizontal Boxcreates a series of boxes to put widgets This a container, you can associate signals if you wish, but they aren't needed. No, I don't know why it's called a horizontal box when it's aligned vertically, except that numerically it runs horizontally (ie a line of numbers, one for each box).
Gtk Vertical BoxVertical Boxcreates a series of boxes to put widgets This is a container, you can associate signals if you wish, but they aren't needed.
Gtk Table Box Table Box creates a series of boxes in a table format This is a container, you can associate signals if you wish, but they aren't needed.
Gtk Fixed Gtk Fixed allows you to fix the position of widgets within the container This container shouldn't really be used. It's comfortable for those coming from a VB background, but it prevents you from learning how to properly use containers in Gtk+. Avoid it if at all possible.
Gtk Horizontal ButtonBox Horizontal ButtonBox a horizontally laid out button box This box is meant to contain buttons.
Gtk Vertical ButtonBox Vertical ButtonBox a vertically laid out button box This box is meant to contain buttons.
Gtk Horizontal PaneHorizontal Panecreates a 'pane' that the user can grab to enlarge or shrink elements in a window This is a container, you can associate signals if you wish, but they aren't needed. The resizing elements are internal.
Gtk Vertical PaneVertical Panecrealtes a 'pane' that the user can grab to enlarge or shrink elements in a window This a container, you can associate signals if you wish, but they aren't needed. The resizing elements are internal.
Gtk Notebook WidgetNotebookThis creates a series of 'file folder' boxes, where if the user clicks on a tab, it can change the page layoutThis is a series of containers, you can associate signals if you wish, but they aren't needed. One thing you will want to do is either label the tabs, or if you wish to use this widget to create an easy 'changing' layout, decide not to show the tabs.
Gtk FrameFrameThis creates a frame, which can be labeled This is a container, you can associate signals if you wish, but they aren't needed. Remember to label the frame, if that is what you want.
Gtk Scrolled Window Scrolled WindowA scrolled window widget This is a container, you can associated signals if you wish, the scrolling should be taken care of automatically.
Gtk Viewport Gtk Viewport creates a viewport The writer is not experience with this widget. See the API.

Previous Next