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

STYLE PROPERTIES

237       'appears-as-list' (boolean : default false : readable / private /
238       static-nick / static-blurb)
239           Whether dropdowns should look like lists rather than menus
240
241       'arrow-size' (integer : default 15 : readable / private / static-nick /
242       static-blurb)
243           The minimum size of the arrow in the combo box
244
245       'shadow-type' (Gtk2::ShadowType : default "none" : readable / private /
246       static-nick / static-blurb)
247           Which kind of shadow to draw around the combo box
248

SIGNALS

250       changed (Gtk2::ComboBox)
251       move-active (Gtk2::ComboBox, Gtk2::ScrollType)
252       boolean = popdown (Gtk2::ComboBox)
253       popup (Gtk2::ComboBox)
254

ENUMS AND FLAGS

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

SEE ALSO

297       Gtk2, Glib::Object, Glib::InitiallyUnowned, Gtk2::Object, Gtk2::Widget,
298       Gtk2::Container, Gtk2::Bin
299
301       Copyright (C) 2003-2011 by the gtk2-perl team.
302
303       This software is licensed under the LGPL.  See Gtk2 for a full notice.
304
305
306
307perl v5.32.1                      2021-01-27                 Gtk2::ComboBox(3)
Impressum