cgtk4

Rendering a Combo Box in GTK 4


I want to render a combo box with an entry field, similar to what is available in gtk4-widget-factory.

comboboxentry in gtk4-widget-factory

In GTK3, we had GtkComboBox with a has-entry property. Setting this property to TRUE rendered an entry field, allowing users to enter a value that was not defined for the combo box.

The documentation for GTK4 says that GtkComboBox has been deprecated in favor of GtkDropDown. How do we render the entry field with this widget?


Solution

  • AFAIK GtkDropDown does not offer free text entry and is not a 1:1 replacement for GtkComboBox, but rather meant to really select one entry from a list of provided options. I would work around by providing a "Custom"/"Other" etc. option in the dropdown and use the callback method to unhide or enable a separate GtkEntry. Even if it seems bulkier at first, it uses basic widgets that exist in any UI framework rather than specialized ones of Gtk.