1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>CheckButton</title><meta name="generator" content="DocBook XSL Stylesheets V1.64.1"><link rel="home" href="index.html" title="Programming with gtkmm2"><link rel="up" href="ch04.html" title="Chapter4.Buttons"><link rel="previous" 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">Prev</a></td><th width="60%" align="center">Chapter4.Buttons</th><td width="20%" align="right"><a accesskey="n" href="ch04s04.html">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></div></div><p>
<tt class="literal">Gtk::CheckButton</tt> inherits from <tt class="literal">Gtk::ToggleButton</tt>. The only real difference between the two is <tt class="literal">Gtk::CheckButton</tt>'s
appearance. You can check, set, and toggle a checkbox using the same
member methods as for <tt class="literal">Gtk::ToggleButton</tt>.
</p><p><a 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="id2503172"></a>Example</h3></div></div><div></div></div><div class="figure"><a name="figure-checkbutton"></a><p class="title"><b>Figure4.2.CheckButton</b></p><div class="screenshot"><div><img src="../figures/checkbutton.png" alt="CheckButton"></div></div></div><p><a href="../../../examples/book/buttons/checkbutton" target="_top">Source Code</a></p><p>File: examplewindow.h
</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>
</p><p>File: examplewindow.cc
</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::slot(*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><p>
</p><p>File: main.cc
</p><pre class="programlisting">
#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;
}
</pre><p>
</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04s02.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="ch04.html">Up</a></td><td width="40%" align="right"><a accesskey="n" href="ch04s04.html">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">Home</a></td><td width="40%" align="right" valign="top">RadioButton</td></tr></table></div></body></html>
|