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
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="highlight.min.css">
<script src="highlight.min.js"></script><script>
hljs.configure({languages: ['cpp']});
hljs.highlightAll();
</script><title>Chapter 13. Combo Boxes</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="Programming with gtkmm 4">
<link rel="up" href="index.html" title="Programming with gtkmm 4">
<link rel="prev" href="sec-dropdown-complex.html" title="Complex Example">
<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 13. Combo Boxes</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-dropdown-complex.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 13. Combo Boxes</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul class="toc">
<li><span class="section"><a href="chapter-combobox.html#sec-combobox-model">The model</a></span></li>
<li><span class="section"><a href="sec-combobox-get.html">The chosen item</a></span></li>
<li><span class="section"><a href="sec-combobox-changes.html">Responding to changes</a></span></li>
<li><span class="section"><a href="combobox-example-full.html">Full Example</a></span></li>
<li><span class="section"><a href="combobox-example-simple.html">Simple Text Example</a></span></li>
<li><span class="section"><a href="sec-comboboxentry.html">ComboBox with an Entry</a></span></li>
</ul>
</div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="icons/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p><code class="classname">Gtk::ComboBox</code> and <code class="classname">Gtk::ComboBoxText</code>
are deprecated since <span class="application">gtkmm</span> 4.10. Use <code class="classname">Gtk::DropDown</code> in new code.
</p></td></tr>
</table></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 check button, 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="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1ComboBox.html" target="_top">Reference</a></p>
<div class="section">
<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"><code class="code">class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumns()
{ add(m_col_id); add(m_col_name); }
Gtk::TreeModelColumn<int> m_col_id;
Gtk::TreeModelColumn<Glib::ustring> m_col_name;
};
ModelColumns m_columns;</code></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-dropdown-complex.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">Complex Example </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>
|