Komponenter
gtkmm applications consist of windows containing widgets, such as buttons and text boxes. In some other systems, widgets are called "controls". For each widget in your application's windows, there is a C++ object in your application's code. So you just need to call a method of the widget's class to affect the visible widget.
Widgets are arranged inside container widgets such as frames and notebooks, in a hierarchy of widgets within widgets. Some of these container widgets, such as Gtk::Grid, are not visible - they exist only to arrange other widgets. Here is some example code that adds 2 Gtk::Button widgets to a Gtk::Box container widget:
m_box.append(m_Button1);
m_box.append(m_Button2);
m_frame.set_child(m_box);
De flesta kapitel i denna bok hanterar specifika komponenter. Se avsnittet Behållarkomponenter för mer detaljer om att lägga till komponenter till behållarkomponenter.
Även om du kan ange layouten och utseendet för fönster och komponenter med C++-kod så kommer du troligen finna det mer bekvämt att designa dina användargränssnitt med Glade och läsa in dem vid körning med Gtk::Builder. Se kapitlet Glade och Gtk::Builder.
Although gtkmm widget instances have lifetimes and scopes just like those of other C++ classes, gtkmm has an optional time-saving feature that you will see in some of the examples. The Gtk::make_managed() allows you to create a new widget and state that it will become owned by the container into which you place it. This allows you to create the widget, add it to the container and not be concerned about deleting it, since that will occur when the parent container (which may itself be managed) is deleted. You can learn more about gtkmm memory management techniques in the Memory Management chapter.