Gtk::CheckButton
inherits directly from
Gtk::Widget
. It is similar to Gtk::ToggleButton
.
The only real difference between the two is Gtk::CheckButton
's
appearance. You can check and set a check button using the same
member methods as for Gtk::ToggleButton
.
File: examplewindow.h
(For use with gtkmm 4)
#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: void on_button_toggled(); //Child widgets: Gtk::CheckButton m_button; }; #endif //GTKMM_EXAMPLE_BUTTONS_H
File: examplewindow.cc
(For use with gtkmm 4)
#include "examplewindow.h" #include <iostream> ExampleWindow::ExampleWindow() : m_button("something") { set_title("checkbutton example"); m_button.signal_toggled().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_toggled) ); m_button.set_margin(10); set_child(m_button); } ExampleWindow::~ExampleWindow() { } void ExampleWindow::on_button_toggled() { std::cout << "The Button was toggled: state=" << (m_button.get_active() ? "true" : "false") << std::endl; }
File: main.cc
(For use with gtkmm 4)
#include "examplewindow.h" #include <gtkmm/application.h> int main(int argc, char *argv[]) { auto app = Gtk::Application::create("org.gtkmm.example"); //Shows the window and returns when it is closed. return app->make_window_and_run<ExampleWindow>(argc, argv); }