CheckButton
Prev | Chapter 4. Buttons | Next

## CheckButton

`Gtk::CheckButton` inherits from `Gtk::ToggleButton`. The only real difference between the two is `Gtk::CheckButton`'s appearance. You can check, set, and toggle a checkbox using the same member methods as for `Gtk::ToggleButton`.

Reference

### Example

Figure 4.2. CheckButton

Source Code

File: examplewindow.h

    #ifndef GTKMM_EXAMPLE_BUTTONS_H
    #define GTKMM_EXAMPLE_BUTTONS_H

    #include <gtkmm/window.h>
    #include <gtkmm/checkbutton.h>

    class ExampleWindow : public Gtk::Window
    {
    public:
      ExampleWindow();
      virtual ~ExampleWindow();

    protected:
      //Signal handlers:
      virtual void on_button_clicked();

      //Child widgets:
      Gtk::CheckButton m_button;
    };

    #endif //GTKMM_EXAMPLE_BUTTONS_H

File: main.cc

    #include <gtkmm/main.h>
    #include "examplewindow.h"

    int main(int argc, char *argv[])
    {
      Gtk::Main kit(argc, argv);

      ExampleWindow window;
      Gtk::Main::run(window); //Shows the window and returns when it is closed.

      return 0;
    }

File: examplewindow.cc

    #include "examplewindow.h"
    #include <iostream>

    ExampleWindow::ExampleWindow()
    : m_button("something")
    {
      set_title("checkbutton example");
      set_border_width(10);

      m_button.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_button_clicked) );

      add(m_button);

      show_all_children();
    }

    ExampleWindow::~ExampleWindow()
    {
    }

    void ExampleWindow::on_button_clicked()
    {
      std::cout << "The Button was clicked: state=" << (m_button.get_active() ? "true" : "false")  << std::endl;
    }

Prev | Up | Next
ToggleButton | Home | RadioButton