Class: Gtk::ComboBoxText
- Defined in:
- lib/gtk4/combo-box-text.rb
Overview
A GtkComboBoxText is a simple variant of GtkComboBox for text-only
use cases.

GtkComboBoxText hides the model-view complexity of GtkComboBox.
To create a GtkComboBoxText, use [ctorGtk.ComboBoxText.new] or
[ctorGtk.ComboBoxText.new_with_entry].
You can add items to a GtkComboBoxText with
[methodGtk.ComboBoxText.append_text],
[methodGtk.ComboBoxText.insert_text] or
[methodGtk.ComboBoxText.prepend_text] and remove options with
[methodGtk.ComboBoxText.remove].
If the GtkComboBoxText contains an entry (via the
[propertyGtk.ComboBox:has-entry] property), its contents can be retrieved
using [methodGtk.ComboBoxText.get_active_text].
You should not call [methodGtk.ComboBox.set_model] or attempt to pack more cells into this combo box via its [ifaceGtk.CellLayout] interface.
GtkComboBoxText as GtkBuildable
The GtkComboBoxText implementation of the GtkBuildable interface supports
adding items directly using the <items> element and specifying <item>
elements for each item. Each <item> element can specify the “id”
corresponding to the appended text and also supports the regular
translation attributes “translatable”, “context” and “comments”.
Here is a UI definition fragment specifying GtkComboBoxText items:
<object class="GtkComboBoxText">
<items>
<item translatable="yes" id="factory">Factory</item>
<item translatable="yes" id="home">Home</item>
<item translatable="yes" id="subway">Subway</item>
</items>
</object>
CSS nodes
combobox
╰── box.linked
├── entry.combo
├── .combo
╰── window.popup
GtkComboBoxText has a single CSS node with name combobox. It adds
the style class .combo to the main CSS nodes of its entry and button
children, and the .linked class to the node of its internal box.
Instance Method Summary collapse
-
#active_text ⇒ String
Returns the currently active string in combo_box.
-
#append(id, text) ⇒ nil
Appends text to the list of strings stored in combo_box.
-
#append_text(text) ⇒ nil
Appends text to the list of strings stored in combo_box.
-
#initialize(options = {}) ⇒ Gtk::Widget
constructor
Creates a new
GtkComboBoxTextwith an entry. -
#initialize_raw ⇒ Gtk::Widget
Creates a new
GtkComboBoxTextwith an entry. -
#insert(position, id, text) ⇒ nil
Inserts text at position in the list of strings stored in combo_box.
-
#insert_text(position, text) ⇒ nil
Inserts text at position in the list of strings stored in combo_box.
-
#prepend(id, text) ⇒ nil
Prepends text to the list of strings stored in combo_box.
-
#prepend_text(text) ⇒ nil
Prepends text to the list of strings stored in combo_box.
-
#remove(position) ⇒ nil
Removes the string at position from combo_box.
-
#remove_all ⇒ nil
Removes all the text entries from the combo box.
Methods inherited from ComboBox
#active, #active=, #active_id, #active_id=, #active_iter, #active_iter=, #active_iter_raw, #button_sensitivity, #button_sensitivity=, #child, #child=, #entry_text_column, #entry_text_column=, #get_active_iter, #has_entry, #has_entry=, #has_entry?, #has_frame=, #has_frame?, #id_column, #id_column=, #model, #model=, #popdown, #popup, #popup_fixed_width, #popup_fixed_width=, #popup_fixed_width?, #popup_for_device, #popup_shown=, #popup_shown?, #row_separator_func, #set_row_separator_func
Methods inherited from Widget
#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #children, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #direction, #direction=, #display, #dispose_template, #drag_check_threshold, #error_bell, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, have_template?, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_action_group_raw, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_size_request, #set_size_request_raw, #set_state_flags, #set_template, #set_template_raw, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #style_context_raw, #template=, template_children, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #translate_coordinates_raw, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=
Constructor Details
#initialize(options = {}) ⇒ Gtk::Widget
Creates a new GtkComboBoxText with an entry.
20 21 22 23 24 25 26 27 28 |
# File 'lib/gtk4/combo-box-text.rb', line 20 def initialize(={}) entry = [:entry] if entry initialize_new_with_entry else initialize_new end end |
Instance Method Details
#active_text ⇒ String
Returns the currently active string in combo_box.
If no row is currently selected, nil is returned. If combo_box contains an entry, this function will return its contents (which will not necessarily be an item from the list).
#append(id, text) ⇒ nil
Appends text to the list of strings stored in combo_box.
If id is non-nil then it is used as the ID of the row.
This is the same as calling [methodGtk.ComboBoxText.insert] with a position of -1.
#append_text(text) ⇒ nil
Appends text to the list of strings stored in combo_box.
This is the same as calling [methodGtk.ComboBoxText.insert_text] with a position of -1.
#initialize_raw ⇒ Gtk::Widget
Creates a new GtkComboBoxText with an entry.
|
|
# File 'lib/gtk4/combo-box-text.rb', line 19
|
#insert(position, id, text) ⇒ nil
Inserts text at position in the list of strings stored in combo_box.
If id is non-nil then it is used as the ID of the row. See [propertyGtk.ComboBox:id-column].
If position is negative then text is appended.
#insert_text(position, text) ⇒ nil
Inserts text at position in the list of strings stored in combo_box.
If position is negative then text is appended.
This is the same as calling [methodGtk.ComboBoxText.insert] with a nil ID string.
#prepend(id, text) ⇒ nil
Prepends text to the list of strings stored in combo_box.
If id is non-nil then it is used as the ID of the row.
This is the same as calling [methodGtk.ComboBoxText.insert] with a position of 0.
#prepend_text(text) ⇒ nil
Prepends text to the list of strings stored in combo_box.
This is the same as calling [methodGtk.ComboBoxText.insert_text] with a position of 0.
#remove(position) ⇒ nil
Removes the string at position from combo_box.
#remove_all ⇒ nil
Removes all the text entries from the combo box.