Gtkmm

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Template:Short description Template:Lowercase Script error: No such module "Labelled list hatnote". Script error: No such module "Infobox".Template:Template otherScript error: No such module "Check for unknown parameters".Template:Main other gtkmm (formerly known as gtk-- or gtk minus minus[1]) 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:

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:

See also

Script error: No such module "Portal".

References

Template:Reflist

External links

Template:GTK

  1. The gtkmm FAQ
  2. Script error: No such module "citation/CS1".
  3. Script error: No such module "citation/CS1".
  4. Script error: No such module "citation/CS1".
  5. Script error: No such module "citation/CS1".
  6. Script error: No such module "citation/CS1".
  7. Script error: No such module "citation/CS1".
  8. Script error: No such module "citation/CS1".
  9. Script error: No such module "citation/CS1".
  10. Script error: No such module "citation/CS1".
  11. Script error: No such module "citation/CS1".
  12. Script error: No such module "citation/CS1".
  13. Script error: No such module "citation/CS1".
  14. Script error: No such module "citation/CS1".
  15. Script error: No such module "citation/CS1".