[Glade-users] Gtk2ComboBox with Glade2



Ashwin Ramachandran wrote:
Hi All,
I used a Gtk2ComboBox in my Glade[Glade2] file and am using libglade to
connect to my Perl-gtk2 application.

I am not able to see the popdown strings in my combobox, even after
attaching the strings
to the combobox. Am using Gtk Version 2.6  and Glade2.
Here is that piece of code:

# Get the combo box widget from the glade object
# I have not defined any combo entries[ie Items] for the combobox in glade,
since
# they are runtime  entries
my $combo_box = $Main_Glade_Ref->get_widget("ComboBox");

# Without using the new_text API, warnings are observed
# So, Using the new_text API to get the text combo box
$combo_box_text = $combo_box->new_text();

#Set the popdown strings
@popdown_strings = ("ACCESS", "STATUS", "DUMMY");
foreach my $string (@popdown_strings) {
 $combo_box_text->append_text($string);
}
$combo_box_text->set_active(0);

At run time, I can see only the combo widget displayed, but not the popdown
strings.

Am I missing something here?

Yes.

gtk_combo_box_new_text() creates a combobox, you dont want that -
you just want your combobox to contain text.

So, add "items" to your combobox via the glade tool, if the combobox
has "items" property set on it - then libglade will create it as
if it had been created with gtk_combo_box_new_text().

If the items are dynamicly created (usually the case), then you could:
    a.) do what gtk_combo_box_new_text() does to the combobox manually in
        your code (i.e. create the liststore with a G_TYPE_STRING column).
    b.) create it with an "items" property set - but just clear the combobox
        text after loading the glade file

Cheers,
                    -Tristan






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