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 in your code. Even when using the widget via a pointer, it's still probably best to make that pointer a member variable of a container class so that you can access it later.
  2. Set the attributes of the widget. If the widget has no default constructor, then you will need to initialize the widget in the initalizer 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::hide() 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 hide() is not called on the child widgets.