This is part of a more general work dedicated to gtkmm accessible here. This example shows how to load and display an image in a window.
Download

gtkmm - example 7 30.43 KB
Source code
main.cpp
#include
#include
int main(int argc, char* argv[])
{
// Initialize gtkmm
Gtk::Main app(argc, argv);
// Create the window
mainwindow w;
// Start main loop
Gtk::Main::run(w);
return 0;
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
// The class mainwindow inherits from Gtk::Window
class mainwindow : public Gtk::Window
{
// Constructor and destructor
public:
mainwindow();
virtual ~mainwindow();
protected:
//Member widgets:
Gtk::Image image;
Gtk::Button buttonQuit;
Gtk::Grid mainGrid;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include
// Constructor of the main Window (build ui interface).
mainwindow::mainwindow()
{
// Initialize the main window and hide the title bar
this->set_border_width(10);
// Load and display the image
image.set("gtk.png");
mainGrid.attach(image,0,0,1,1);
// Add the Quit button
buttonQuit.add_label("Quit");
buttonQuit.signal_pressed().connect(sigc::mem_fun(*this,&mainwindow::close));
mainGrid.attach(buttonQuit,0,2,1,1);
// Display the main grid in the main window
mainGrid.show_all();
// Insert the grid in the main window
add(mainGrid);
}
// Destructor of the class
mainwindow::~mainwindow()
{}