File: chapter-dropdown.html

package info (click to toggle)
gtkmm-documentation 4.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,772 kB
  • sloc: cpp: 15,541; javascript: 1,208; makefile: 1,080; python: 401; xml: 106; perl: 67; sh: 8
file content (138 lines) | stat: -rw-r--r-- 5,763 bytes parent folder | download
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
137
138
<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 12. The DropDown Widget</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-treeview-examples.html" title="Examples">
<link rel="next" href="sec-dropdown-get.html" title="The selected 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 12. The DropDown Widget</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-dropdown-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-dropdown"></a>Chapter 12. The DropDown Widget</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul class="toc">
<li><span class="section"><a href="chapter-dropdown.html#sec-dropdown-model">The model</a></span></li>
<li><span class="section"><a href="sec-dropdown-get.html">The selected item</a></span></li>
<li><span class="section"><a href="sec-dropdown-changes.html">Responding to changes</a></span></li>
<li><span class="section"><a href="sec-dropdown-simple.html">Simple String Example</a></span></li>
<li><span class="section"><a href="sec-dropdown-search.html">Examples with a Search Entry</a></span></li>
<li><span class="section"><a href="sec-dropdown-complex.html">Complex Example</a></span></li>
</ul>
</div>


<p>The <code class="classname">DropDown</code> widget is an alternative to the deprecated
<code class="classname">ComboBox</code>. It uses list models instead of tree models,
and the content is displayed using widgets instead of cell renderers.
</p>

<p>The <code class="classname">DropDown</code> widget offers a list of choices in a
dropdown menu. If appropriate, it can show extra information about each item,
such as text, a picture, or a check button. The <code class="classname">DropDown</code> widget
can optionally have an <code class="classname">Entry</code> in the dropdown menu, allowing
the user to search in a long list.
</p>

<p>The list is provided via a <code class="classname">Gio::ListModel</code>, and data
from this model is added to the <code class="classname">DropDown</code>'s view with
signal handlers connected to a <code class="classname">SignalListItemFactory</code>.
This provides flexibility, but the <code class="classname">StringList</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_1DropDown.html" target="_top">Reference</a></p>

<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-dropdown-model"></a>The model</h2></div></div></div>


<p>The model for a <code class="classname">DropDown</code> can be defined and filled
exactly as for a <code class="classname">ListView</code> or a <code class="classname">ColumnView</code>.
It must be a subclass of <code class="classname">Glib::Object</code>.
For instance, you might have a <code class="classname">DropDown</code> with one integer
and one text column, like so:
</p>
<pre class="programlisting"><code class="code">class ModelColumns : public Glib::Object
{
public:
  int m_col_id;
  Glib::ustring m_col_name;

  static Glib::RefPtr&lt;ModelColumns&gt; create(
    int col_id, const Glib::ustring&amp; col_name)
  {
    return Glib::make_refptr_for_instance&lt;ModelColumns&gt;(
      new ModelColumns(col_id, col_name));
  }

protected:
  ModelColumns(int col_id, const Glib::ustring&amp; col_name)
  : m_col_id(col_id), m_col_name(col_name)
  {}
};

Glib::RefPtr&lt;Gio::ListStore&lt;ModelColumns&gt;&gt; m_ListStore;
</code></pre>

<p>After appending rows to this model, you should provide the model to the
<code class="classname">DropDown</code> with the <code class="methodname">set_model()</code> method.
Unless you use the <code class="classname">StringList</code> model, you also need to set
a <code class="classname">ListItemFactory</code> with <code class="methodname">set_factory()</code>.
If you want the items in the dropdown menu to look different from the item
in the <code class="classname">DropDown</code> widget, you also need to set a separate
<code class="classname">ListItemFactory</code> with <code class="methodname">set_list_factory()</code>.
</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-dropdown-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 selected item</td>
</tr>
</table>
</div>
</body>
</html>