1Gtk2::ComboBox(3)     User Contributed Perl Documentation    Gtk2::ComboBox(3)
2
3
4

NAME

6       Gtk2::ComboBox - A widget used to choose from a list of items
7

SYNOPSIS

9         # the easy way:
10         $combobox = Gtk2::ComboBox->new_text;
11         foreach (@strings) {
12             $combobox->append_text ($_);
13         }
14         $combobox->prepend_text ($another_string);
15         $combobox->insert_text ($index, $yet_another_string);
16         $combobox->remove_text ($index);
17         $text = $combobox->get_active_text;
18
19
20         # the full-featured way.
21         # a combo box that shows stock ids and their images:
22         use constant ID_COLUMN => 0;
23         $model = Gtk2::ListStore->new ('Glib::String');
24         foreach (qw(gtk-ok gtk-cancel gtk-yes gtk-no gtk-save gtk-open)) {
25             $model->set ($model->append, ID_COLUMN, $_);
26         }
27         $combo_box = Gtk2::ComboBox->new ($model);
28         # to display anything, you must pack cell renderers into
29         # the combobox, which implements the Gtk2::CellLayout interface.
30         $renderer = Gtk2::CellRendererPixbuf->new;
31         $combo_box->pack_start ($renderer, FALSE);
32         $combo_box->add_attribute ($renderer, stock_id => ID_COLUMN);
33         $renderer = Gtk2::CellRendererText->new;
34         $combo_box->pack_start ($renderer, TRUE);
35         $combo_box->add_attribute ($renderer, text => ID_COLUMN);
36
37         # select by index
38         $combo_box->set_active ($index);
39         $active_index = $combo_box->get_active;
40
41         # or by iter
42         $combo_box->set_active_iter ($iter);
43         $active_iter = $combo_box->get_active_iter;
44

DESCRIPTION

46       Gtk2::ComboBox is a widget that allows the user to choose from a list
47       of valid choices.  The ComboBox displays the selected choice.  When
48       activated, the ComboBox displays a popup which allows the user to make
49       a new choice.
50
51       Unlike its predecessors Gtk2::Combo and Gtk2::OptionMenu, the
52       Gtk2::ComboBox uses the model-view pattern; the list of valid choices
53       is specified in the form of a tree model, and the display of the
54       choices can be adapted to the data in the model by using cell
55       renderers, as you would in a tree view.  This is possible since
56       ComboBox implements the Gtk2::CellLayout interface.  The tree model
57       holding the valid choices is not restricted to a flat list; it can be a
58       real tree, and the popup will reflect the tree structure.
59
60       In addition to the model-view API, ComboBox offers a simple API which
61       is suitable for text-only combo boxes, and hides the complexity of
62       managing the data in a model.  It consists of the methods "new_text",
63       "append_text", "insert_text", "prepend_text", "remove_text" and
64       "get_active_text".
65

HIERARCHY

67         Glib::Object
68         +----Glib::InitiallyUnowned
69              +----Gtk2::Object
70                   +----Gtk2::Widget
71                        +----Gtk2::Container
72                             +----Gtk2::Bin
73                                  +----Gtk2::ComboBox
74

INTERFACES

76         Glib::Object::_Unregistered::AtkImplementorIface
77         Gtk2::Buildable
78         Gtk2::CellLayout
79         Gtk2::CellEditable
80

METHODS

82   widget = Gtk2::ComboBox->new ($model=undef)
83       ·   $model (Gtk2::TreeModel)
84
85   widget = Gtk2::ComboBox->new_text
86   widget = Gtk2::ComboBox->new_with_model ($model=undef)
87       ·   $model (Gtk2::TreeModel)
88
89   integer = $combo_box->get_active
90   treeiter = $combo_box->get_active_iter
91   $combo_box->set_active_iter ($iter)
92       ·   $iter (Gtk2::TreeIter or undef)
93
94   $combo_box->set_active ($index)
95       ·   $index (integer)
96
97   string = $combo_box->get_active_text
98       Since: gtk+ 2.6
99
100   boolean = $combo_box->get_add_tearoffs
101       Since: gtk+ 2.6
102
103   $combo_box->set_add_tearoffs ($add_tearoffs)
104       ·   $add_tearoffs (boolean)
105
106       Since: gtk+ 2.6
107
108   $combo_box->append_text ($text)
109       ·   $text (string)
110
111   sensitivitytype = $combo_box->get_button_sensitivity
112       Since: gtk+ 2.14
113
114   $combo_box->set_button_sensitivity ($sensitivity)
115       ·   $sensitivity (Gtk2::SensitivityType)
116
117       Since: gtk+ 2.14
118
119   integer = $combo_box->get_column_span_column
120       Since: gtk+ 2.6
121
122   $combo_box->set_column_span_column ($column_span)
123       ·   $column_span (integer)
124
125   boolean = $combo_box->get_focus_on_click
126       Since: gtk+ 2.6
127
128   $combo_box->set_focus_on_click ($focus_on_click)
129       ·   $focus_on_click (boolean)
130
131       Since: gtk+ 2.6
132
133   $combo_box->insert_text ($position, $text)
134       ·   $position (integer)
135
136       ·   $text (string)
137
138   treemodel = $combo_box->get_model
139   $combo_box->set_model ($model)
140       ·   $model (Gtk2::TreeModel or undef)
141
142       Note that setting "undef" for no model is new in Gtk 2.6.  (Both here
143       or via "set_property".)
144
145   $combo_box->popdown
146   $combo_box->popup
147   $combo_box->prepend_text ($text)
148       ·   $text (string)
149
150   $combo_box->remove_text ($position)
151       ·   $position (integer)
152
153   $combo_box->set_row_separator_func ($func, $data=undef)
154       ·   $func (scalar)
155
156       ·   $data (scalar)
157
158       Since: gtk+ 2.6
159
160   integer = $combo_box->get_row_span_column
161       Since: gtk+ 2.6
162
163   $combo_box->set_row_span_column ($row_span)
164       ·   $row_span (integer)
165
166   string = $combo_box->get_title
167       Since: gtk+ 2.10
168
169   $combo_box->set_title ($title)
170       ·   $title (string)
171
172       Since: gtk+ 2.10
173
174   integer = $combo_box->get_wrap_width
175       Since: gtk+ 2.6
176
177   $combo_box->set_wrap_width ($width)
178       ·   $width (integer)
179

PROPERTIES

181       'active' (integer : default -1 : readable / writable / private)
182           The item which is currently active
183
184       'add-tearoffs' (boolean : default false : readable / writable /
185       private)
186           Whether dropdowns should have a tearoff menu item
187
188       'button-sensitivity' (Gtk2::SensitivityType : default "auto" : readable
189       / writable / private)
190           Whether the dropdown button is sensitive when the model is empty
191
192       'column-span-column' (integer : default -1 : readable / writable /
193       private)
194           TreeModel column containing the column span values
195
196       'entry-text-column' (integer : default -1 : readable / writable /
197       private)
198           The column in the combo box's model to associate with strings from
199           the entry if the combo was created with #GtkComboBox:has-entry =
200           %TRUE
201
202       'focus-on-click' (boolean : default true : readable / writable /
203       private)
204           Whether the combo box grabs focus when it is clicked with the mouse
205
206       'has-entry' (boolean : default false : readable / writable / construct-
207       only / private)
208           Whether combo box has an entry
209
210       'has-frame' (boolean : default true : readable / writable / private)
211           Whether the combo box draws a frame around the child
212
213       'model' (Gtk2::TreeModel : default undef : readable / writable /
214       private)
215           The model for the combo box
216
217       'popup-shown' (boolean : default false : readable / private)
218           Whether the combo's dropdown is shown
219
220       'row-span-column' (integer : default -1 : readable / writable /
221       private)
222           TreeModel column containing the row span values
223
224       'tearoff-title' (string : default undef : readable / writable /
225       private)
226           A title that may be displayed by the window manager when the popup
227           is torn-off
228
229       'wrap-width' (integer : default 0 : readable / writable / private)
230           Wrap width for laying out the items in a grid
231

STYLE PROPERTIES

233       'appears-as-list' (boolean : default false : readable / private)
234           Whether dropdowns should look like lists rather than menus
235
236       'arrow-size' (integer : default 15 : readable / private)
237           The minimum size of the arrow in the combo box
238
239       'shadow-type' (Gtk2::ShadowType : default "none" : readable / private)
240           Which kind of shadow to draw around the combo box
241

SIGNALS

243       changed (Gtk2::ComboBox)
244       move-active (Gtk2::ComboBox, Gtk2::ScrollType)
245       boolean = popdown (Gtk2::ComboBox)
246       popup (Gtk2::ComboBox)
247

ENUMS AND FLAGS

249   enum Gtk2::ScrollType
250       ·   'none' / 'GTK_SCROLL_NONE'
251
252       ·   'jump' / 'GTK_SCROLL_JUMP'
253
254       ·   'step-backward' / 'GTK_SCROLL_STEP_BACKWARD'
255
256       ·   'step-forward' / 'GTK_SCROLL_STEP_FORWARD'
257
258       ·   'page-backward' / 'GTK_SCROLL_PAGE_BACKWARD'
259
260       ·   'page-forward' / 'GTK_SCROLL_PAGE_FORWARD'
261
262       ·   'step-up' / 'GTK_SCROLL_STEP_UP'
263
264       ·   'step-down' / 'GTK_SCROLL_STEP_DOWN'
265
266       ·   'page-up' / 'GTK_SCROLL_PAGE_UP'
267
268       ·   'page-down' / 'GTK_SCROLL_PAGE_DOWN'
269
270       ·   'step-left' / 'GTK_SCROLL_STEP_LEFT'
271
272       ·   'step-right' / 'GTK_SCROLL_STEP_RIGHT'
273
274       ·   'page-left' / 'GTK_SCROLL_PAGE_LEFT'
275
276       ·   'page-right' / 'GTK_SCROLL_PAGE_RIGHT'
277
278       ·   'start' / 'GTK_SCROLL_START'
279
280       ·   'end' / 'GTK_SCROLL_END'
281
282   enum Gtk2::SensitivityType
283       ·   'auto' / 'GTK_SENSITIVITY_AUTO'
284
285       ·   'on' / 'GTK_SENSITIVITY_ON'
286
287       ·   'off' / 'GTK_SENSITIVITY_OFF'
288

SEE ALSO

290       Gtk2, Glib::Object, Glib::InitiallyUnowned, Gtk2::Object, Gtk2::Widget,
291       Gtk2::Container, Gtk2::Bin
292
294       Copyright (C) 2003-2011 by the gtk2-perl team.
295
296       This software is licensed under the LGPL.  See Gtk2 for a full notice.
297
298
299
300perl v5.28.0                      2018-07-18                 Gtk2::ComboBox(3)
Impressum