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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter4.Buttons</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="index.html" title="Programming with gtkmm2"><link rel="previous" href="ch03s06.html" title="Hello World in gtkmm"><link rel="next" href="ch04s02.html" title="ToggleButton"></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">Chapter4.Buttons</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s06.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="ch04s02.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="sec-buttonwidget"></a>Chapter4.Buttons</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch04.html#sec-Pushbuttons">Button</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04.html#id2502702">Constuctors</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2502788">Example</a></span></dt><dt><span class="sect2"><a href="ch04.html#id2502903">Signals</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04s02.html">ToggleButton</a></span></dt><dt><span class="sect1"><a href="ch04s03.html">CheckButton</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04s03.html#id2503172">Example</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch04s04.html">RadioButton</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch04s04.html#id2503302">Groups</a></span></dt><dt><span class="sect2"><a href="ch04s04.html#id2442971">Methods</a></span></dt><dt><span class="sect2"><a href="ch04s04.html#id2443003">Example</a></span></dt></dl></dd></dl></div><p>
gtkmm provides four basic types of buttons:
</p><p>
</p><div class="variablelist"><dl><dt><span class="term">Push-Buttons</span></dt><dd><p>
<a href="../../reference/html/classGtk_1_1Button.html" target="_top"><tt class="literal">Gtk::Button</tt></a>. Standard buttons, usually
marked with a label or picture. Pushing one triggers an action. See the <a href="ch04.html#sec-Pushbuttons" title="Button">Button</a> section.
</p></dd><dt><span class="term">Toggle buttons</span></dt><dd><p>
<a href="../../reference/html/classGtk_1_1ToggleButton.html" target="_top"><tt class="literal">Gtk::ToggleButton</tt></a>.
Unlike a normal Button, which springs back up, a ToggleButton stays down until you
press it again. It might be useful as an on/off switch. See the <a href="ch04s02.html" title="ToggleButton">ToggleButton</a> section.
</p></dd><dt><span class="term">Checkboxes</span></dt><dd><p>
<a href="../../reference/html/classGtk_1_1CheckButton.html" target="_top"><tt class="literal">Gtk::CheckButton</tt></a>.
These act like ToggleButtons, but show their state in small squares,
with their label at the side. They should be used in most situations
which require an on/off setting.
See the <a href="ch04s03.html" title="CheckButton">CheckBox</a> section.
</p></dd><dt><span class="term">Radio buttons</span></dt><dd><p>
<a href="../../reference/html/classGtk_1_1RadioButton.html" target="_top"><tt class="literal">Gtk::RadioButton</tt></a>.
Named after the station selectors on old car
radios, these buttons are used in groups for options which are
mutually exclusive. Pressing one causes all the
others in its group to turn off. They are similar to
CheckBoxes (a small widget with a label at the side), but usually
look different.
See the <a href="ch04s04.html" title="RadioButton">RadioButton</a> section.
</p></dd></dl></div><p>
</p><p>
Note that, due to GTK+'s theming system, the appearance of these
widgets will vary. In the case of checkboxes and radio buttons, they
may vary considerably.
</p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec-Pushbuttons"></a>Button</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2502702"></a>Constuctors</h3></div></div><div></div></div><p>
There are two ways to create a Button. You can specify a label
string in the <tt class="literal">Gtk::Button</tt> constructor,
or set it later with <tt class="literal">set_label()</tt>.
</p><p>To define an accelerator key for keyboard navigation, place an underscore before one of the label's characters and specify <tt class="literal">true</tt> for the optional <tt class="literal">mnemonic</tt> parameter. For instance:
</p><pre class="programlisting">
Gtk::Button* pButton = new Gtk::Button("_Something", true);
</pre><p>
</p><p>
Wherever possible you should use Stock items, to ensure consistency with other applications, and to improve the appearance of your applications by using icons. For instance,
</p><pre class="programlisting">
Gtk::Button* pButton = new Gtk::Button(Gtk::Stock::OK);
</pre><p>
This will use standard text, in all languages, with standard keyboard accelerators, with a standard icon.
</p><p>
<tt class="literal">Gtk::Button</tt> is also
a container so you could put any other widget, such as a
<tt class="literal">Gtk::Image</tt> into it.
</p><p><a href="../../reference/html/classGtk_1_1Button.html" target="_top">Reference</a></p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2502788"></a>Example</h3></div></div><div></div></div><p>
This example creates a button with a picture and a label.
</p><div class="figure"><a name="figure-buttons"></a><p class="title"><b>Figure4.1.buttons example</b></p><div class="screenshot"><div><img src="../figures/buttons.png" alt="buttons example"></div></div></div><p><a href="../../../examples/book/buttons/button" target="_top">Source Code</a></p><p>File: buttons.h
</p><pre class="programlisting">
#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
</pre><p>
</p><p>File: buttons.cc
</p><pre class="programlisting">
#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::slot(*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;
}
</pre><p>
</p><p>File: main.cc
</p><pre class="programlisting">
#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;
}
</pre><p>
</p><p>
Note that the <tt class="literal">XPMLabelBox</tt> class can be used to place XPMs and
labels into any widget that can be a container.
</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2502903"></a>Signals</h3></div></div><div></div></div><p>
The <tt class="literal">Gtk::Button</tt> widget has the following signals, but most of the time you will just handle the <tt class="literal">clicked</tt> signal:
</p><p>
</p><div class="variablelist"><dl><dt><span class="term"><tt class="literal">pressed</tt></span></dt><dd><p>
Emitted when the button is pressed.
</p></dd><dt><span class="term"><tt class="literal">released</tt></span></dt><dd><p>
Emitted when the button is released.
</p></dd><dt><span class="term"><tt class="literal">clicked</tt></span></dt><dd><p>
Emitted when the button is pressed and released.
</p></dd><dt><span class="term"><tt class="literal">enter</tt></span></dt><dd><p>
Emitted when the mouse pointer moves over the button's window.
</p></dd><dt><span class="term"><tt class="literal">leave</tt></span></dt><dd><p>
Emitted when the mouse pointer leaves the button's window.
</p></dd></dl></div><p>
</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s06.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><a accesskey="n" href="ch04s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Hello World in gtkmm</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">ToggleButton</td></tr></table></div></body></html>
|