A single-line text entry widget.
<picture> <source srcset="entry-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkEntry"
src="entry.png"> </picture>
A fairly large set of key bindings are supported by default. If the entered text is longer than the allocation of the widget, the widget
will scroll so that the cursor position is visible.
When using an entry for passwords and other sensitive information, it can be put into “password mode” using [
method@Gtk.Entry.set_visibility]. In this mode, entered text is displayed using a “invisible” character. By default, GTK picks the
best invisible character that is available in the current font, but it can be changed with [method@Gtk.Entry.set_invisible_char].
`GtkEntry` has the ability to display progress or activity information behind the text. To make an entry display such information, use [
method@Gtk.Entry.set_progress_fraction] or [method@Gtk.Entry.set_progress_pulse_step].
Additionally, `GtkEntry` can show icons at either side of the entry. These icons can be activatable by clicking, can be set up as drag
source and can have tooltips. To add an icon, use [method@Gtk.Entry.set_icon_from_gicon] or one of the various other functions that set an
icon from an icon name or a paintable. To trigger an action when the user clicks an icon, connect to the [signal@Gtk.Entry:
GtkEntry:icon-presss] signal. To allow DND operations from an icon, use [method@Gtk.Entry.set_icon_drag_source]. To set a tooltip
on an icon, use [method@Gtk.Entry.set_icon_tooltip_text] or the corresponding function for markup.
Note that functionality or information that is only available by clicking on an icon in an entry may not be accessible at all to users
which are not able to use a mouse or other pointing device. It is therefore recommended that any such functionality should also be
available by other means, e.g. via the context menu of the entry.
CSS nodes
``` entry.flat[.error] ├── text[.readonly] ├── image.left ├── image.right ╰── [progress[.pulse]] ```
`GtkEntry` has a main node with the name entry. Depending on the properties of the entry, the style classes .read-only and .flat may
appear. The style classes .warning and .error may also be used with entries.
When the entry shows icons, it adds subnodes with the name image and the style class .left or .right, depending on where the icon
appears.
When the entry shows progress, it adds a subnode with the name progress. The node has the style class .pulse when the shown progress is
pulsing.
For all the subnodes added to the text node in various situations, see [class@Gtk.Text].
GtkEntry as GtkBuildable
The `GtkEntry` implementation of the `GtkBuildable` interface supports a custom `<attributes>` element, which supports any number
of `<attribute>` elements. The `<attribute>` element has attributes named “name“, “value“, “start“ and “end“
and allows you to specify `PangoAttribute` values for this label.
An example of a UI definition fragment specifying Pango attributes: ```xml <object class="GtkEntry"> <attributes> <
attribute name="weight" value="PANGO_WEIGHT_BOLD"/> <attribute name="background" value="red" start="5" end="10"/> <
/attributes> </object> ```
The start and end attributes specify the range of characters to which the Pango attribute applies. If start and end are not specified,
the attribute is applied to the whole text. Note that specifying ranges does not make much sense with translatable attributes. Use markup
embedded in the translatable content instead.
Accessibility
`GtkEntry` uses the [enum@Gtk.AccessibleRole.text_box] role.
- public bool get_activates_default ()
- public float get_alignment ()
- public unowned EntryBuffer get_buffer ()
Get the `GtkEntryBuffer` object which holds the text for this widget.
- public unowned EntryCompletion get_completion ()
Returns the auxiliary completion object currently in use by
this.
- public int get_current_icon_drag_source ()
Returns the index of the icon which is the source of the current DND
operation, or -1.
- public unowned Adjustment get_cursor_hadjustment ()
Retrieves the horizontal cursor adjustment for the entry.
- public bool get_has_frame ()
- public bool get_icon_activatable (EntryIconPosition icon_pos)
Returns whether the icon is activatable.
- public int get_icon_at_pos (int x, int y)
Finds the icon at the given position and return its index.
- public unowned Icon get_icon_gicon (EntryIconPosition icon_pos)
Retrieves the `GIcon` used for the icon.
- public unowned string get_icon_name (EntryIconPosition icon_pos)
Retrieves the icon name used for the icon.
- public unowned Pixbuf get_icon_pixbuf (EntryIconPosition icon_pos)
Retrieves the image used for the icon.
- public bool get_icon_sensitive (EntryIconPosition icon_pos)
Returns whether the icon appears sensitive or insensitive.
- public unowned string get_icon_stock (EntryIconPosition icon_pos)
Retrieves the stock id used for the icon, or
null if there is no icon or if the icon was set by some other method (e.
- public ImageType get_icon_storage_type (EntryIconPosition icon_pos)
Gets the type of representation being used by the icon to store image
data.
- public string? get_icon_tooltip_markup (EntryIconPosition icon_pos)
Gets the contents of the tooltip on the icon at the specified position
in this.
- public string? get_icon_tooltip_text (EntryIconPosition icon_pos)
Gets the contents of the tooltip on the icon at the specified position
in this.
- public unowned Window get_icon_window (EntryIconPosition icon_pos)
- public unowned Border get_inner_border ()
- public unichar get_invisible_char ()
Retrieves the character displayed in place of the actual text in
“password mode”.
- public unowned Layout get_layout ()
Gets the Layout
used to display the entry.
- public void get_layout_offsets (out int x, out int y)
Obtains the position of the
Layout used to render text in the entry, in widget coordinates.
- public int get_max_length ()
Retrieves the maximum allowed length of the text in
this.
- public bool get_overwrite_mode ()
Gets whether the `GtkEntry` is in overwrite mode.
- public double get_progress_fraction ()
Returns the current fraction of the task that’s been completed.
- public double get_progress_pulse_step ()
- public unowned string get_text ()
Retrieves the contents of the entry widget.
- public virtual void get_text_area_size (out int x, out int y, out int width, out int height)
Calculate the size of the text area, which is its allocated width and
requested height, minus space for margins and borders.
- public uint16 get_text_length ()
Retrieves the current length of the text in
this.
- public unowned Window get_text_window ()
- public bool get_visibility ()
Retrieves whether the text in this
is visible.
- public int get_width_chars ()
- public bool im_context_filter_keypress (EventKey event)
Allow the Entry input method to internally
handle key press and release events.
- public int layout_index_to_text_index (int layout_index)
Converts from a position in the entry’s
Layout (returned by
get_layout) to a position in the entry contents (returned by get_text).
- public void progress_pulse ()
Indicates that some progress is made, but you don’t know how much.
- public void reset_im_context ()
Reset the input method context of the entry if needed.
- public void set_activates_default (bool setting)
Sets whether pressing Enter in the this
will activate the default widget for the window containing the entry.
- public void set_alignment (float xalign)
Sets the alignment for the contents of the entry.
- public void set_buffer (EntryBuffer buffer)
Set the `GtkEntryBuffer` object which holds the text for this widget.
- public void set_completion (EntryCompletion completion)
Sets completion to be the auxiliary completion object to
use with this.
- public void set_cursor_hadjustment (Adjustment adjustment)
Hooks up an adjustment to the cursor position in an entry, so that
when the cursor is moved, the adjustment is scrolled to show that position.
- public void set_has_frame (bool setting)
Sets whether the entry has a beveled frame around it.
- public void set_icon_activatable (EntryIconPosition icon_pos, bool activatable)
Sets whether the icon is activatable.
- public void set_icon_drag_source (EntryIconPosition icon_pos, TargetList target_list, DragAction actions)
Sets up the icon at the given position as drag source.
- public void set_icon_from_gicon (EntryIconPosition icon_pos, Icon? icon)
Sets the icon shown in the entry at the specified position from the
current icon theme.
- public void set_icon_from_icon_name (EntryIconPosition icon_pos, string? icon_name)
Sets the icon shown in the entry at the specified position from the
current icon theme.
- public void set_icon_from_pixbuf (EntryIconPosition icon_pos, Pixbuf? pixbuf)
Sets the icon shown in the specified position using a pixbuf.
- public void set_icon_from_stock (EntryIconPosition icon_pos, string? stock_id)
Sets the icon shown in the entry at the specified position from a
stock image.
- public void set_icon_sensitive (EntryIconPosition icon_pos, bool sensitive)
Sets the sensitivity for the specified icon.
- public void set_icon_tooltip_markup (EntryIconPosition icon_pos, string? tooltip)
Sets tooltip as the contents of the tooltip for the icon
at the specified position.
- public void set_icon_tooltip_text (EntryIconPosition icon_pos, string? tooltip)
Sets tooltip as the contents of the tooltip for the icon
at the specified position.
- public void set_inner_border (Border border)
Sets entry’s inner-border property
to border, or clears it if null is passed.
- public void set_invisible_char (unichar ch)
Sets the character to use in place of the actual text in “password
mode”.
- public void set_max_length (int max)
Sets the maximum allowed length of the contents of the widget.
- public void set_overwrite_mode (bool overwrite)
Sets whether the text is overwritten when typing in the `GtkEntry`.
- public void set_progress_fraction (double fraction)
Causes the entry’s progress indicator to “fill in” the given
fraction of the bar.
- public void set_progress_pulse_step (double fraction)
Sets the fraction of total entry width to move the progress bouncing
block for each pulse.
- public void set_text (string text)
Sets the text in the widget to the given value, replacing the current
contents.
- public void set_visibility (bool visible)
Sets whether the contents of the entry are visible or not.
- public void set_width_chars (int n_chars)
Changes the size request of the entry to be about the right size for
n_chars characters.
- public int text_index_to_layout_index (int text_index)
Converts from a position in the entry contents (returned by
get_text) to a position in the entry’s
Layout (returned by
get_layout, with text retrieved via get_text).
- public void unset_invisible_char ()
Unsets the invisible char, so that the default invisible char is used
again.