Next Previous Contents

5. Widget Overview

The general steps to creating a widget in GTK are:

  1. create an instance of one of various widget classes. These are all detailed in this section.
  2. Connect all signals and events we wish to use to the appropriate handlers.
  3. Set the attributes of the widget.
  4. Pack the widget into a container using the appropriate call such as GTK_CONTAINER::add() or GTK_BOX::pack_*().
  5. show the widget.

Procedure GTK_WIDGET::show lets GTK know that we are done setting the attributes of the widget, and it is ready to be displayed. You may also use GTK_WIDGET::hide to make it disappear again. The order in which you show the widgets is not important, but I suggest showing the window last so the whole window pops up at once rather than seeing the individual widgets come up on the screen as they're formed. The children of a widget (a window is a widget too) will not be displayed until the window itself is shown using the show() procedure.

5.1 Widget Hierarchy

For your reference, here is the class hierarchy tree used to implement widgets.

 GTK_OBJECT
  +GTK_WIDGET
  | +GTK_MISC
  | | +GTK_LABEL
  | | | +GTK_ACCEL_LABEL
  | | | `GTK_TIPS_QUERY
  | | +GTK_ARROW
  | | +GTK_IMAGE
  | | `GTK_PIXMAP
  | +GTK_CONTAINER
  | | +GTK_BIN
  | | | +GTK_ALIGNMENT
  | | | +GTK_FRAME
  | | | | `GTK_ASPECT_FRAME
  | | | +GTK_BUTTON
  | | | | +GTK_TOGGLE_BUTTON
  | | | | | `GTK_CHECK_BUTTON
  | | | | |   `GTK_RADIO_BUTTON
  | | | | `GTK_OPTION_MENU
  | | | +GTK_ITEM
  | | | | +GTK_MENU_ITEM
  | | | | | +GTK_CHECK_MENU_ITEM
  | | | | | | `GTK_RADIO_MENU_ITEM
  | | | | | `GTK_TEAROFF_MENU_ITEM
  | | | | +GTK_LIST_ITEM
  | | | | `GTK_TREE_ITEM
  | | | +GTK_WINDOW
  | | | | +GTK_COLOR_SELECTION_DIALOG
  | | | | +GTK_DIALOG
  | | | | | `GTK_INPUT_DIALOG
  | | | | +GTK_DRAW_WINDOW
  | | | | +GTK_FILE_SELECTION
  | | | | +GTK_FONT_SELECTION_DIALOG
  | | | | `GTK_PLUG
  | | | +GTK_EVENT_BOX
  | | | +GTK_HANDLE_BOX
  | | | +GTK_SCROLLED_WINDOW
  | | | `GTK_VIEWPORT
  | | +GTK_BOX
  | | | +GTK_BUTTON_BOX
  | | | | +GTK_HBUTTON_BOX
  | | | | `GTK_VBUTTON_BOX
  | | | +GTK_VBOX
  | | | | +GTK_COLOR_SELECTION
  | | | | `GTK_GAMMA_CURVE
  | | | `GTK_HBOX
  | | |   +GTK_COMBO
  | | |   `GTK_STATUSBAR
  | | +GTK_CLIST
  | | | `GTK_CTREE
  | | +GTK_FIXED
  | | +GTK_NOTEBOOK
  | | | `GTK_FONT_SELECTION
  | | +GTK_PANED
  | | | +GTK_HPANED
  | | | `GTK_VPANED
  | | +GTK_LAYOUT
  | | +GTK_LIST
  | | +GTK_MENU_SHELL
  | | | +GTK_MENU_BAR
  | | | `GTK_MENU
  | | +GTK_PACKER
  | | +GTK_SOCKET
  | | +GTK_TABLE
  | | +GTK_TOOLBAR
  | | `GTK_TREE
  | +GTK_CALENDAR
  | +GTK_DRAWING_AREA
  | | `GTK_CURVE
  | +GTK_EDITABLE
  | | +GTK_ENTRY
  | | | `GTK_SPIN_BUTTON
  | | `GTK_TEXT
  | +GTK_RULER
  | | +GTK_HRULER
  | | `GTK_VRULER
  | +GTK_RANGE
  | | +GTK_SCALE
  | | | +GTK_HSCALE
  | | | `GTK_VSCALE
  | | `GTK_SCROLLBAR
  | |   +GTK_HSCROLLBAR
  | |   `GTK_VSCROLLBAR
  | +GTK_SEPARATOR
  | | +GTK_HSEPARATOR
  | | `GTK_VSEPARATOR
  | +GTK_PREVIEW
  | `GTK_PROGRESS
  |   `GTK_PROGRESS_BAR
  +GTK_DATA
  | +GTK_ADJUSTMENT
  | `GTK_TOOLTIPS
  `GTK_ITEM_FACTORY

5.2 Widgets Without Windows

The following widgets do not have an associated window. If you want to capture events, you'll have to use the GtkEventBox. See the section on the EventBox widget.

GTK_ALIGNMENT
GTK_ARROW
GTK_BIN
GTK_BOX
GTK_IMAGE
GTK_ITEM
GTK_LABEL
GTK_PIXMAP
GTK_SCROLLED_WINDOW
GTK_SEPARATOR
GTK_TABLE
GTK_ASPECT_FRAME
GTK_FRAME
GTK_VBOX
GTK_HBOX
GTK_VSEPARATOR
GTK_HSEPARATOR

We'll further our exploration of GTK by examining each widget in turn, creating a few simple functions to display them. Another good source is the testgtk program that comes with VEGTK.


Next Previous Contents