Cet article fait parti d’un ensemble d’exemples et d’articles sur gtkmm consultables ici. Cette exemple montre comment créer une application avec des onglets. Le premier onglet contient un bouton et le deuxième onglet contient juste un label.
Téléchargement

gtkmm - example 24 20.06 KB
Code source
main.cpp
#include
#include
int main(int argc, char* argv[])
{
// Initialize gtkmm and create the main window
Glib::RefPtr app = Gtk::Application::create(argc, argv, "www.lucidarme.me");
// Create the window
mainwindow window;
// Start main loop
return app->run(window);
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include
// The class mainwindow inherits from Gtk::Window
class mainwindow : public Gtk::Window
{
// Constructor and destructor
public:
mainwindow();
virtual ~mainwindow();
protected:
//Signal handlers (run when the button is clicked)
void on_button_clicked();
//Page selector
Gtk::Notebook Selector;
// Button for the first page
Gtk::Button Button;
// Label for the second page
Gtk::Label Label;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
// Constructor of the main Window (build ui interface).
mainwindow::mainwindow()
{
// Resize the main window and set border width
this->resize(400,200);
set_border_width(5);
// Add the label and connect the button
Button.add_label("Page 1 (button)");
Button.signal_clicked().connect(sigc::mem_fun(*this,&mainwindow::on_button_clicked));
// Set label text
Label.set_text("Page 2 (label)");
// Add the widgets (button and label) in the notebook
Selector.append_page(Button, "First");
Selector.append_page(Label, "Second");
// This packs the button into the Window (a container).
add(Selector);
show_all_children();
}
// Destructor of the class
mainwindow::~mainwindow()
{}
// Call when the button os clicked and display my url
void mainwindow::on_button_clicked()
{
std::cout << "www.lucidarme.me" << std::endl;
}