gtkmm: |
The C++ Interface to Gtk+ |
Buttons and Signals |
Buttons are widgets that creates a signal when clicked on, plain and simple.
signal_action()
where action defines the
event action of the signal.Glib::SignalProxy0 signal_activate ()
Glib::SignalProxy0 signal_clicked ()
Glib::SignalProxy0 signal_enter ()
Glib::SignalProxy0 signal_leave ()
Glib::SignalProxy0 signal_pressed ()
Glib::SignalProxy0 signal_released ()
signal_clicked
is your friend.main.cc:
#include <gtkmm/main.h>
#include "buttons.h"
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Buttons buttons;
Gtk::Main::run(buttons); //Shows the window and returns when it is closed.
return 0;
}
buttons.h:
#ifndef GTKMM_EXAMPLE_BUTTONS_H
#define GTKMM_EXAMPLE_BUTTONS_H
#include <gtkmm/window.h>
#include <gtkmm/button.h>
class Buttons : public Gtk::Window
{
public:
Buttons();
virtual ~Buttons();
protected:
//Signal handlers:
virtual void on_button_clicked();
//Child widgets:
Gtk::Button m_button;
};
#endif //GTKMM_EXAMPLE_BUTTONS_H
buttons.cc:
#include "buttons.h"
#include <iostream>
Buttons::Buttons()
{
m_button.add_pixlabel("info.xpm", "cool button");
set_title("Pixmap'd buttons!");
set_border_width(10);
m_button.signal_clicked().connect( sigc::mem_fun(*this, &Buttons::on_button_clicked) );
add(m_button);
show_all_children();
}
Buttons::~Buttons()
{
}
void Buttons::on_button_clicked()
{
std::cout << "The Button was clicked." << std::endl;
}