Re: Making Glade created ComboBox behave like Gtk2::ComboBox->new_text?

Martin Junius said:
Daniel Kasak wrote:

You mean the 'ComboBox' from Gtk-2.2? If so, that's been depreciated for
quite a while. What version of Gtk to do have? If you've got Gtk-2.4 or
higher, you should use a 'ComboBoxEntry'. It allows you to use a
Gtk2::ListStore ( as you're trying to do above ) to store values for
your combo box. I think that's what your problem here is - you're trying
to use an old ComboBox as a ComboBoxEntry.

In my understanding, ComboBoxEntry is just a specialization of ComboBox,
ie a CombBox plus user entry. OptionMenu is deprecated, but ComboBox?

I think he meant GtkCombo, which is the old, deprecated combo box widget.

ComboBox and ComboBoxEntry are the replacements for OptionMenu and Combo.

Meanwhile, I found out that I have to add the following code (cbox is
the widget from Glade):

    my $model = new Gtk2::ListStore('Glib::String');
    my $renderer = new Gtk2::CellRendererText;
    $cbox->pack_start($renderer, FALSE);
    $cbox->set_attributes($renderer, text => 0);

Is this the canonical way? The code was shamelessly copied from

That's how you set up a ComboBox by hand.  It also happens to be how
gtk_combo_box_new_text() sets up the widget.

Then I can use

    for ... {

This works mostly by accident, because you set up your model the same way that
new_text() does.

append_text() merely does this (in C rather than perl, but):

   sub append_text {
      my ($combobox, $text) = @_;
      my $model = $combobox->get_model;
      $model->set ($model->append, 0, $text);

muppet <scott at asofyet dot org>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]