Gtk2-Perl Study Guide: Gaining an understanding of Gtk2-Perl | ||
|---|---|---|
| Prev | Chapter 15. Gtk2::ComboBox and Gtk2::ComboBoxEntry Widgets | Next |
Gtk2::ComboBoxEntry Widgets The Gtk2::ComboBoxEntry widget is subclassed from the Gtk2::ComboBox widget and contains a child Gtk2::Entry widget that has its contents set by selecting an item in the dropdown list or by direct text entry either from the keyboard or by pasting from a Gtk2::Clipboard or a selection.
Gtk2::ComboBoxEntry Use Like the Gtk2::ComboBox, the Gtk2::ComboBoxEntry can be created using the convenience method:
widget = Gtk2::ComboBoxEntry->new_textThe
Gtk2::ComboBoxEntry should be populated using the Gtk2::ComboBox convenience methods described in Basic Gtk2::ComboBox Use.
Since a Gtk2::ComboBoxEntry widget is a Gtk2::Bin widget its child Gtk2::Entry widget is available using the "child" or the "get_child()" methods:
$entry = $combobox_entry->child; $entry = $combobox_entry->get_child;You can retrieve the
Gtk2::Entry text using its "get_text()" method.
Like the Gtk2::ComboBox, you can track changes in the active list item by connecting to the "changed" signal. Unfortunately, this doesn't help track changes to the text in the Entry child that are direct entry. When a direct entry is made to the child Gtk2::Entry widget the "changed" signal will be emitted but the index returned by the "get_active()" method will be -1. To track all changes to the Gtk2::Entry text, you'll have to use the Gtk2::Entry's "changed" signal. For example:
($combo_box_entry->child)->signal_connect('changed' => sub {
my ($entry) = @_;
print "I Like ". $entry->get_text."\n";
});
will print out the text after every change in the child Gtk2::Entry widget. For example, the 'gtk2_combo_box_entry.pl' program demonstrates the use of the convenience API.
![]() | When the |
Gtk2::ComboBoxEntry Use The constructor for a Gtk2::ComboBoxEntry is:
$entry = Gtk2::ComboBoxEntry->new ($model, $text_column) * $text_column (integer) * $model (Gtk2::TreeModel)where $model is a
Gtk2::TreeModel and $text_column is the number of the column in $model to use for setting the list items.
Creating a Gtk2::ComboBoxEntry using the convenience method "new_text" is equivalent to the following:
my $list_store = Gtk2::ListStore->new(qw/Glib::String/); my $entry = Gtk2::ComboBoxEntry->new ($list_store, 0);
The Gtk2::ComboBoxEntry adds a couple of methods that are used to set and retrieve the Gtk2::TreeModel column number to use for setting the list item strings:
integer = $entry_box->get_text_column $entry_box->set_text_column ($text_column) * $text_column (integer)The text column can also be retrieved and set using the
"text-column" property.