Using a gtkmm widget

Our examples all tend to have the same structure. They follow these steps for using a Widget:

  1. Declare a variable of the type of Widget you wish to use, generally as member variable of a derived container class. You could also declare a pointer to the widget type, and then create it with new or Gtk::make_managed() in your code.

  2. Set the attributes of the widget. If the widget has no default constructor, then you will need to initialize the widget in the initializer list of your container class's constructor.

  3. Connect any signals you wish to use to the appropriate handlers.

  4. Pack the widget into a container using the appropriate call, e.g. Gtk::Box::append().

If you don't want all widgets to be shown, call Gtk::Widget::set_visible(false) on the widgets that you don't want to show. If a container widget is hidden, all of its child widgets are also hidden, even if set_visible(false) is not called on the child widgets.