Here is a link to a more exhaustive tutorial (where I learned myself):Programming with gtkmm
Also visit this link which has detailed information on each class/namespace/file:
gtkmm 2.4 Documentation
Quick Introduction:
Abstract:
This tutorial covers how to create a GUI including one button arranged within a single frame. In another post I will eventually cover the basics of how to create a "more" section (i.e. hidden widgets). This is a very basic GUI that simply allows you to run commands depending on the callback of the button.
Idea:
The basic idea of gtkmm (GTK in general) is to create a gui where all elements are relative in position and size (for the most part). Each element is considered a widget and the things that hold it, containers. Elements are typically considered children, and containers parent(s).
Main.h
Add:
#include
#include "gui.h"
Main.cpp
Add:
Gtk::Main kit(argc,argv);
gui gui;
Gtk::Main::run(gui);
gui.h
Add:
class gui : public Gtk::Window
{
public:
gui();
virtual ~gui();
protected:
//Signal handlers:
virtual void on_button_clicked();
//WINDOW - Child widgets
Gtk::Frame window_frame;
Gtk::VBox window_box;
Gtk::Button window_button,
gui.cpp
Add:
// Sets the Window Title
set_title("Window Title");
// Sets the border width of the window
set_border_width(10);
// Add the box to the window (the window can contain one widget/container)
add(window_box);
// Add the frame to the box (boxes can contain multiple widgets/containers)
window_box.pack_start(window_frame);
// Label the frame
window_frame.set_label("Main");
// Add a button to the frame (frames can contain one widget/container)
window_frame.add(button);
// This is how you do a call back (to a function where you define whatever you want)
button.signal_clicked().connect(sigc::mem_fun(*this,
&gui::on_button_clicked));
That's it. Just define your on_button_clicked() function and you are all set to make a simple GUI.
No comments:
Post a Comment