Använda en gtkmm-komponent

Våra exempel tenderar att ha samma struktur. De följer dessa steg för att använda en 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. Anslut alla signaler som du vill använda till lämpliga hanterare.

  4. Packa komponenten i en behållare med lämpligt anrop, t.ex. Gtk::Box::append().

Om du inte vill att alla komponenter ska visas anropar du Gtk::Widget::set_visible(false) på komponenterna som du inte vill ska visas. Om en behållarkomponent är dold så är även alla dess underordnade komponenter dolda, även om set_visible(false) inte anropas på de underordnade komponenterna.