[Glade-users] combo box question




I have a combobox created in Glade. In my Python code, I populate the
combobox list with items.  When I tab or click into the box, I want the
item list to dropdown automatically, without clicking on the arrow. Also,
when user starts typing into the box, I would like the focus jump to the
item that closely matches what user typed... or something like that... a
standard combo box funtionality. How would I accomplish this?

You may try to emit "popup" signal which by default gets emitted on
Alt+Down, but you should keep in mind that the menu gets keyboard focus,
so the user won't be able to type anything into the entry while it's
shown. In other words there's no way to accomplish what you want using
this popup menu (although it might be a sort of answer to your next
question).

The right way to do it would be creating GtkEntryCompletion and attaching
it to the entry. It would show dropdown menu with suggestions when the
user starts typing. That menu has nothing to do with combobox menu, but
you can reuse one treemodel for both.

Another way I am looking is to prevent the user from typing anything into
the combobox and let him only pick from the dropdown down list. How do I
prevent the user from typing into the combobox?

The straightforward way is to use proper widget intended for it, namely
plain combobox, not comboboxentry. Or if you insist on status quo, filter
"key-press-event". Yet another option could be getting actual entry widget
from inside of combobox with gtk_bin_get_child() and making it
insensitive.

Looking back at the amount of questions you have, may I suggest
http://www.gtkbook.com/ as a good source of answers to many of them. It
doesn't target Python, and it might be slightly dated by now, but it still
good investment which provides perfect introduction into the matter you're
trying to conquer.





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