Skip to content
Surf Wiki
Save to docs
general/articles-with-example-c-code

From Surf Wiki (app.surf) — the open knowledge base

Gtkmm

GUI Toolkit


GUI Toolkit

FieldValue
logo
screenshot
released
latest release date
latest preview date
programming language[C++](c)
platformGTK
genreLanguage binding
licenseGNU Lesser General Public License
website

Main article: List of language bindings for GTK

gtkmm (formerly known as gtk-- or gtk minus minus) is the official C++ interface for the popular GUI library GTK. gtkmm is free software distributed under the GNU Lesser General Public License (LGPL).

gtkmm allows the creation of user interfaces either in code or with the Glade Interface Designer, using the Gtk::Builder class. Other features include typesafe callbacks, a comprehensive set of graphical control elements, and the extensibility of widgets via inheritance.

Features

Because gtkmm is the official C++ interface of the GUI library GTK, C++ programmers can use the common OOP techniques such as inheritance, and C++-specific facilities such as STL (In fact, many of the gtkmm interfaces, especially those for widget containers, are designed to be similar to the Standard Template Library (STL)).

Main features of gtkmm are listed as follows:

  • Use inheritance to derive custom widgets.
  • Type-safe signal handlers, in standard C++.
  • Polymorphism.
  • Use of Standard C++ Library, including strings, containers, and iterators.
  • Full internationalization with UTF-8.
  • Complete C++ memory management.
    • Object composition.
    • Automatic de-allocation of dynamically allocated widgets.
  • Full use of C++ namespaces.
  • No macros.
  • Cross-platform: Linux (gcc, LLVM), FreeBSD (gcc, LLVM), NetBSD (gcc), Solaris (gcc, Forte), Win32 (gcc, MSVC++), macOS (gcc), others.

Hello World in gtkmm

//HelloWorldWindow.h

#ifndef HELLOWORLDWINDOW_H
#define HELLOWORLDWINDOW_H

#include <gtkmm/window.h>
#include <gtkmm/button.h>

// Derive a new window widget from an existing one.
// This window will only contain a button labelled "Hello World"
class HelloWorldWindow : public Gtk::Window
{
  public:
    HelloWorldWindow();

  protected:
    Gtk::Button hello_world;
};

#endif
//HelloWorldWindow.cc

#include <iostream>
#include "HelloWorldWindow.h"

HelloWorldWindow::HelloWorldWindow() : hello_world("Hello World")
{
    // Set the title of the window.
    set_title("Hello World");

    // Add the member button to the window.
    set_child(hello_world);

    // Handle the 'clicked' signal.
    hello_world.signal_clicked().connect([] () {
          std::cout << "Hello world" << std::endl;
    });
}
//main.cc

#include <gtkmm/application.h>
#include "HelloWorldWindow.h"

int main(int argc, char *argv[]) 
{
    // Create an application object.
    auto app = Gtk::Application::create("org.gtkmm.example");

    // Create a hello world window object and return when it is closed.
    return app->make_window_and_run<HelloWorldWindow>(argc, argv);
}

The above program will create a window with a button labeled "Hello World". The button sends "Hello world" to standard output when clicked.

The program is run using the following commands:

$ g++ -std=c++17 *.cc -o example `pkg-config gtkmm-4.0 --cflags --libs`
$ ./example

This is usually done using a simple makefile.

Applications

Some notable applications that use gtkmm include:

  • Amsynth
  • Cadabra (computer program)
  • Inkscape Vector graphics drawing.
  • Horizon EDA an Electronic Design Automation package for printed circuit board design.
  • PDF Slicer A simple application to extract, merge, rotate and reorder pages of PDF documents.
  • Workrave Assists in recovery and prevention of RSI.
  • Gnome System Monitor
  • Gigedit
  • GParted disk partitioning tool.
  • Nemiver GUI for the GNU debugger gdb.
  • PulseAudio tools: pavucontrol, paman, paprefs pavumeter,
  • RawTherapee
  • GNOME Referencer document organiser and bibliography manager
  • Seq24
  • Synfig Studio
  • Linthesia
  • MySQL Workbench Administrator Database GUI.
  • Ardour Open Source digital audio workstation (DAW) for Linux and MacOS.
  • Gnote desktop notetaking application.
  • VisualBoyAdvance
  • VMware Workstation and VMware Player both use gtkmm for their Linux ports.

References

References

  1. [https://gtkmm.gnome.org/en/faq.html The gtkmm FAQ]
  2. "Debian -- Details of package amsynth in jessie".
  3. "Debian -- Details of package cadabra in jessie".
  4. "Debian -- Details of package gnome-system-monitor in jessie".
  5. "Debian -- Details of package gigedit in jessie".
  6. "Debian -- Details of package pavucontrol in jessie".
  7. "Debian -- Details of package paman in jessie".
  8. "Debian -- Details of package paprefs in jessie".
  9. "Debian -- Details of package pavumeter in jessie".
  10. "Debian -- Details of package rawtherapee in jessie".
  11. "Debian -- Details of package seq24 in jessie".
  12. "Debian -- Details of package synfigstudio in jessie".
  13. "Debian -- Details of package linthesia in jessie".
  14. "Debian -- Details of package mysql-workbench in jessie".
  15. "Debian -- Details of package visualboyadvance-gtk in jessie".
Info: Wikipedia Source

This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.

Want to explore this topic further?

Ask Mako anything about Gtkmm — get instant answers, deeper analysis, and related topics.

Research with Mako

Free with your Surf account

Content sourced from Wikipedia, available under CC BY-SA 4.0.

This content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.

Report