<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>CheckButton</title> <link rel="stylesheet" href="style.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.73.2"> <link rel="start" href="index.html" title="Programming with gtkmm"> <link rel="up" href="ch04.html" title="Chapter 4. Buttons"> <link rel="prev" href="ch04s02.html" title="ToggleButton"> <link rel="next" href="ch04s04.html" title="RadioButton"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">CheckButton</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="ch04s02.html"><img src="../icons/prev.png" alt="Prev"></a> </td> <th width="60%" align="center">Chapter 4. Buttons</th> <td width="20%" align="right"> <a accesskey="n" href="ch04s04.html"><img src="../icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="sect1" lang="en"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="sec-Checkboxes"></a>CheckButton</h2></div></div></div> <p> <code class="classname">Gtk::CheckButton</code> inherits from <code class="classname">Gtk::ToggleButton</code>. The only real difference between the two is <code class="classname">Gtk::CheckButton</code>'s appearance. You can check, set, and toggle a checkbox using the same member methods as for <code class="classname">Gtk::ToggleButton</code>. </p> <p><a class="ulink" href="../../reference/html/classGtk_1_1CheckButton.html" target="_top">Reference</a></p> <div class="sect2" lang="en"> <div class="titlepage"><div><div><h3 class="title"> <a name="id2571315"></a>Example</h3></div></div></div> <div class="figure"> <a name="figure-checkbutton"></a><p class="title"><b>Figure 4.2. CheckButton</b></p> <div class="figure-contents"><div class="screenshot"><div><img src="../figures/checkbutton.png" alt="CheckButton"></div></div></div> </div> <br class="figure-break"><p><a class="ulink" href="../../../examples/book/buttons/checkbutton" target="_top">Source Code</a></p> <p>File: <code class="filename">examplewindow.h</code> </p> <pre class="programlisting"> #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 </pre> <p>File: <code class="filename">main.cc</code> </p> <pre class="programlisting"> #include <gtkmm/main.h> #include "examplewindow.h" int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); ExampleWindow window; //Shows the window and returns when it is closed. Gtk::Main::run(window); return 0; } </pre> <p>File: <code class="filename">examplewindow.cc</code> </p> <pre class="programlisting"> #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; } </pre> </div> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="ch04s02.html"><img src="../icons/prev.png" alt="Prev"></a> </td> <td width="20%" align="center"><a accesskey="u" href="ch04.html"><img src="../icons/up.png" alt="Up"></a></td> <td width="40%" align="right"> <a accesskey="n" href="ch04s04.html"><img src="../icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">ToggleButton </td> <td width="20%" align="center"><a accesskey="h" href="index.html"><img src="../icons/home.png" alt="Home"></a></td> <td width="40%" align="right" valign="top"> RadioButton</td> </tr> </table> </div> </body> </html>