Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > e40b0b2b839eccdb3c85993a7b738115 > files > 12

gtkmm-documentation-3.24.0-1.mga7.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 10. Combo Boxes</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Programming with gtkmm 3">
<link rel="up" href="index.html" title="Programming with gtkmm 3">
<link rel="prev" href="sec-treeview-examples.html" title="Examples">
<link rel="next" href="sec-combobox-get.html" title="The chosen item">
</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">Chapter 10. Combo Boxes</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-treeview-examples.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="sec-combobox-get.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="chapter-combobox"></a>Chapter 10. Combo Boxes</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul class="toc">
<li><span class="sect1"><a href="chapter-combobox.html#sec-combobox-model">The model</a></span></li>
<li><span class="sect1"><a href="sec-combobox-get.html">The chosen item</a></span></li>
<li><span class="sect1"><a href="sec-combobox-changes.html">Responding to changes</a></span></li>
<li><span class="sect1"><a href="combobox-example-full.html">Full Example</a></span></li>
<li><span class="sect1"><a href="combobox-example-simple.html">Simple Text Example</a></span></li>
<li><span class="sect1"><a href="sec-comboboxentry.html">ComboBox with an Entry</a></span></li>
</ul>
</div>
<p>The <code class="classname">ComboBox</code> widget offers a list (or tree) of choices in a dropdown menu. If appropriate, it can show extra information about each item, such as text, a picture, a checkbox, or a progress bar. The <code class="classname">ComboBox</code> widget usually restricts the user to the available choices, but it can optionally have an <code class="classname">Entry</code>, allowing the user to enter arbitrary text if none of the available choices are suitable.
</p>
<p>The list is provided via a <code class="classname">TreeModel</code>, and columns from this model are added to the ComboBox's view with the <code class="methodname">ComboBox::pack_start()</code> method. This provides flexibility and compile-time type-safety, but the <code class="classname">ComboBoxText</code> class provides a simpler text-based specialization in case that flexibility is not required.
</p>
<p><a class="ulink" href="http://developer.gnome.org/gtkmm/3.24/classGtk_1_1ComboBox.html" target="_top">Reference</a></p>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-combobox-model"></a>The model</h2></div></div></div>
<p>The model for a ComboBox can be defined and filled exactly as for a <code class="classname">TreeView</code>. For instance, you might derive a ComboBox class with one integer and one text column, like so:
</p>
<pre class="programlisting">ModelColumns()
{ add(m_col_id); add(m_col_name); }

  Gtk::TreeModelColumn&lt;int&gt; m_col_id;
  Gtk::TreeModelColumn&lt;Glib::ustring&gt; m_col_name;
};

ModelColumns m_columns;</pre>
<p>After appending rows to this model, you should provide the model to the <code class="classname">ComboBox</code> with the <code class="methodname">set_model()</code> method. Then use the <code class="methodname">pack_start()</code> or <code class="methodname">pack_end()</code> methods to specify what columns will be displayed in the ComboBox. As with the TreeView you may either use the default cell renderer by passing the <code class="classname">TreeModelColumn</code> to the pack methods, or you may instantiate a specific <code class="classname">CellRenderer</code> and specify a particular mapping with either <code class="methodname">add_attribute()</code> or <code class="methodname">set_cell_data_func()</code>. Note that these methods are in the <code class="classname">CellLayout</code> base class.</p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-treeview-examples.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="sec-combobox-get.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Examples </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"> The chosen item</td>
</tr>
</table>
</div>
</body>
</html>