Table of Contents
gtkmm-4.0 is a new version of the gtkmm API that installs in parallel with the older gtkmm-2.4 and gtkmm-3.0 APIs. The last version of the gtkmm-3.0 API is gtkmm 3.24. gtkmm 4 has no major fundamental differences to gtkmm 3 but does make several changes (both small and large ones) that were not possible while maintaining binary compatibility. If you never used the gtkmm-3.0 API then you can safely ignore this chapter.
gtkmm 4's library is called
libgtkmm-4.0 rather than
libgtkmm-3.0 and installs its headers in a similarly-versioned
directory, so your pkg-config check should ask for
gtkmm-4.0 rather than
gtkmm-4.0 is used in combination with glibmm-2.68,
which sets the global locale for your program. The older glibmm-2.4
does not do that, and gtkmm-3.0 does it only to some extent. What this means is
briefly that if your gtkmm-3.0 program contains a call to
std::locale::global(std::locale("")), you can probably remove it.
If you don't want glibmm or gtkmm
to set the global locale for you, you should add a call to
Glib::set_init_to_users_preferred_locale(false) before any call to
There are lots and lots of differences between gtkmm-3.0 and gtkmm-4.0. The following lists are not complete.
Some new classes were added in gtkmm 4 and glibmm 2.68:
Gtk::Snapshot: These classes are needed only for writing custom widgets. See the Custom Widgets section.
Gdk::Windowhas been renamed to
Gtk::Windowkeeps its name.)
Gdk::DrawingContexthas been removed.
Gtk::Clipboardhas been replaced by the new
Gdk::DragContexthas been split into
There have also been several changes to the API, which you will probably encounter when porting code that used gtkmm-3.0 and glibmm-2.4. Here is a short list:
Gtk::Actionableinterface instead of the removed
get_preferred_*_vfunc()s have been replaced by
measure_vfunc(). This change only affects custom widgets.
sigc::slots use the
sigc::slot<void(int, int)>instead of
sigc::slot<void, int, int>.
Gtk::DrawingAreauses a draw function instead of the draw signal.
Glib::SListHandlehave been removed. They were used in glibmm-2.4, but not used in gtkmm-3.0. If you've ever used these classes, replace them with a standard C++ container, such as
Gtk::Containerhas been removed.
Gtk::Widget::show_all()has been removed. The default value of
Gtk::Widget::property_visible()has been changed from
Gtk::Widget. In most cases you can use one of the subclasses of
Gtk::EventControlleras a replacement. For instance, use
Glib::RefPtris an alias for
std::shared_ptr. If you make your own
Glib::ObjectBase-derived classes with
create()methods that return a
Glib::RefPtr, you must use
Gtk::Box::pack_end()have been removed. Use the new
Gtk::ButtonBoxhas been removed.
Gtk::RadioButtonGrouphave been removed. Use
All deprecated API was removed in gtkmm 4.0 and glibmm 2.68, though there will be new deprecations in future versions.
As a first step to porting your source code to gtkmm-4.0 you should probably ensure that your application builds with the deprecated gtkmm-3.0 and glibmm-2.4 API disabled, by defining the macros GTKMM_DISABLE_DEPRECATED, GDKMM_DISABLE_DEPRECATED, GLIBMM_DISABLE_DEPRECATED and GIOMM_DISABLE_DEPRECATED. There are some autotools macros that can help with this by defining them optionally at build time. See the Porting from gtkmm-2.4 to gtkmm-3.0 wiki page for more details.
See also Migrating from GTK 3.x to GTK 4.
Many classes are deprecated since gtkmm 4.10. They can still be used in gtkmm4 applications, provided GTKMM_DISABLE_DEPRECATED and GDKMM_DISABLE_DEPRECATED are not defined. There are also many new classes in gtkmm 4.10, which replace some of the deprecated classes. Some example programs in this tutorial use classes deprecated since gtkmm 4.10. Some other programs use classes available since gtkmm 4.10.
Deprecated classes: AppChooser, AppChooserButton, AppChooserDialog, AppChooserWidget, CellArea, CellAreaBox, CellAreaContext, CellLayout, CellRenderer, CellRendererAccel, CellRendererCombo, CellRendererPixbuf, CellRendererProgress, CellRendererSpin, CellRendererSpinner, CellRendererText, CellRendererToggle, CellView, ComboBox, ComboBoxText, EntryCompletion, IconView, ListStore, ListViewText, StyleContext, TreeDragDest, TreeDragSource, TreeIter and other classes in treeiter.h, TreeModel, TreeModelFilter, TreeModelSort, TreePath, TreeRowReference, TreeSelection, TreeSortable, TreeStore, TreeView, TreeViewColumn, namespace CellRenderer_Generation, namespace TreeView_Private, ColorButton, ColorChooser, ColorChooserDialog, FileChooser, FileChooserDialog, FileChooserNative, FileChooserWidget, FontButton, FontChooser, FontChooserDialog, FontChooserWidget, MessageDialog, TreeModelColumn, TreeModelColumnRecord, InfoBar, Assistant, AssistantPage, LockButton, Statusbar, VolumeButton.
New classes and enums: AlertDialog, ColorDialog, ColorDialogButton, ColumnViewSorter, FileDialog, FontDialog, FontDialogButton, FileLauncher, UriLauncher, ATContext, enums DialogError, FontLevel, Collation.
In most cases there are replacements for the deprecated classes. See the reference documentation.