GtkText — A simple single-line text entry field
gboolean | activates-default | Read / Write |
PangoAttrList * | attributes | Read / Write |
GtkEntryBuffer * | buffer | Read / Write / Construct |
gboolean | enable-emoji-completion | Read / Write |
GMenuModel * | extra-menu | Read / Write |
char * | im-module | Read / Write |
GtkInputHints | input-hints | Read / Write |
GtkInputPurpose | input-purpose | Read / Write |
guint | invisible-char | Read / Write |
gboolean | invisible-char-set | Read / Write |
int | max-length | Read / Write |
gboolean | overwrite-mode | Read / Write |
char * | placeholder-text | Read / Write |
gboolean | propagate-text-width | Read / Write |
int | scroll-offset | Read |
PangoTabArray * | tabs | Read / Write |
gboolean | truncate-multiline | Read / Write |
gboolean | visibility | Read / Write |
void | activate | Action |
void | backspace | Action |
void | copy-clipboard | Action |
void | cut-clipboard | Action |
void | delete-from-cursor | Action |
void | insert-at-cursor | Action |
void | insert-emoji | Action |
void | move-cursor | Action |
void | paste-clipboard | Action |
void | preedit-changed | Action |
void | toggle-overwrite | Action |
menu.popup | ||
text.redo | ||
text.undo | ||
misc.toggle-visibility | ||
misc.insert-emoji | ||
selection.select-all | ||
selection.delete | ||
clipboard.paste | ||
clipboard.copy | ||
clipboard.cut |
struct | GtkText |
GObject ╰── GInitiallyUnowned ╰── GtkWidget ╰── GtkText
GtkText implements GtkAccessible, GtkBuildable, GtkConstraintTarget and GtkEditable.
#include <gtk/gtk.h>
The GtkText widget is a single line text entry widget.
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 gtk_text_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 gtk_text_set_invisible_char()
.
If you are looking to add icons or progress display in an entry, look at GtkEntry. There other alternatives for more specialized use cases, such as GtkSearchEntry.
If you need multi-line editable text, look at GtkTextView.
text[.read-only] ├── placeholder ├── undershoot.left ├── undershoot.right ├── [selection] ├── [block-cursor] ╰── [window.popup]
GtkText has a main node with the name text. Depending on the properties of the widget, the .read-only style class may appear.
When the entry has a selection, it adds a subnode with the name selection.
When the entry is in overwrite mode, it adds a subnode with the name block-cursor that determines how the block cursor is drawn.
The CSS node for a context menu is added as a subnode below text as well.
The undershoot nodes are used to draw the underflow indication when content is scrolled out of view. These nodes get the .left and .right style classes added depending on where the indication is drawn.
When touch is used and touch selection handles are shown, they are using CSS nodes with name cursor-handle. They get the .top or .bottom style class depending on where they are shown in relation to the selection. If there is just a single handle for the text cursor, it gets the style class .insertion-cursor.
GtkText uses the GTK_ACCESSIBLE_ROLE_NONE role, which causes it to be skipped for accessibility. This is because GtkText is expected to be used as a delegate for a GtkEditable implementation that will be represented to accessibility.
GtkWidget *
gtk_text_new_with_buffer (GtkEntryBuffer *buffer
);
Creates a new self with the specified text buffer.
buffer | The buffer to use for the new GtkText. |
a new GtkText
void gtk_text_set_buffer (GtkText *self
,GtkEntryBuffer *buffer
);
Set the GtkEntryBuffer object which holds the text for this widget.
self | a GtkText | |
buffer |
GtkEntryBuffer *
gtk_text_get_buffer (GtkText *self
);
Get the GtkEntryBuffer object which holds the text for this self.
self | a GtkText |
void gtk_text_set_visibility (GtkText *self
,gboolean visible
);
Sets whether the contents of the self are visible or not. When visibility is set to FALSE
, characters are displayed as the invisible char, and will also appear that way when the text in the self widget is copied to the clipboard.
By default, GTK picks the best invisible character available in the current font, but it can be changed with gtk_text_set_invisible_char()
.
Note that you probably want to set “input-purpose” to GTK_INPUT_PURPOSE_PASSWORD
or GTK_INPUT_PURPOSE_PIN
to inform input methods about the purpose of this self, in addition to setting visibility to FALSE
.
self | a GtkText | |
visible |
|
gboolean
gtk_text_get_visibility (GtkText *self
);
Retrieves whether the text in self
is visible. See gtk_text_set_visibility()
.
self | a GtkText |
TRUE
if the text is currently visible
void gtk_text_set_invisible_char (GtkText *self
,gunichar ch
);
Sets the character to use in place of the actual text when gtk_text_set_visibility()
has been called to set text visibility to FALSE
. i.e. this is the character used in “password mode” to show the user how many characters have been typed.
By default, GTK picks the best invisible char available in the current font. If you set the invisible char to 0, then the user will get no feedback at all; there will be no text on the screen as they type.
self | a GtkText | |
ch | a Unicode character |
gunichar
gtk_text_get_invisible_char (GtkText *self
);
Retrieves the character displayed in place of the real characters for entries with visibility set to false. Note that GTK does not compute this value unless it needs it, so the value returned by this function is not very useful unless it has been explicitly set with gtk_text_set_invisible_char()
self | a GtkText |
the current invisible char, or 0, if text
does not show invisible text at all.
void
gtk_text_unset_invisible_char (GtkText *self
);
Unsets the invisible char previously set with gtk_text_set_invisible_char()
. So that the default invisible char is used again.
self | a GtkText |
void gtk_text_set_overwrite_mode (GtkText *self
,gboolean overwrite
);
Sets whether the text is overwritten when typing in the GtkText.
self | a GtkText | |
overwrite | new value |
gboolean
gtk_text_get_overwrite_mode (GtkText *self
);
Gets the value set by gtk_text_set_overwrite_mode()
.
self | a GtkText |
whether the text is overwritten when typing.
void gtk_text_set_max_length (GtkText *self
,int length
);
Sets the maximum allowed length of the contents of the widget.
If the current contents are longer than the given length, then they will be truncated to fit.
This is equivalent to getting self
's GtkEntryBuffer and calling gtk_entry_buffer_set_max_length()
on it. ]|
self | a GtkText | |
length | the maximum length of the self, or 0 for no maximum. (other than the maximum length of entries.) The value passed in will be clamped to the range 0-65536. |
int
gtk_text_get_max_length (GtkText *self
);
Retrieves the maximum allowed length of the text in self
. See gtk_text_set_max_length()
.
This is equivalent to getting self
's GtkEntryBuffer and calling gtk_entry_buffer_get_max_length()
on it.
self | a GtkText |
the maximum allowed number of characters in GtkText, or 0 if there is no maximum.
guint16
gtk_text_get_text_length (GtkText *self
);
Retrieves the current length of the text in self
.
This is equivalent to getting self
's GtkEntryBuffer and calling gtk_entry_buffer_get_length()
on it.
self | a GtkText |
the current number of characters in GtkText, or 0 if there are none.
void gtk_text_set_activates_default (GtkText *self
,gboolean activates
);
If activates
is TRUE
, pressing Enter in the self
will activate the default widget for the window containing the self. This usually means that the dialog box containing the self will be closed, since the default widget is usually one of the dialog buttons.
self | a GtkText | |
activates |
|
gboolean
gtk_text_get_activates_default (GtkText *self
);
Retrieves the value set by gtk_text_set_activates_default()
.
self | a GtkText |
TRUE
if the self will activate the default widget
void gtk_text_set_placeholder_text (GtkText *self
,const char *text
);
Sets text to be displayed in self
when it is empty.
This can be used to give a visual hint of the expected contents of the self.
self | a GtkText | |
text | a string to be displayed when | [nullable] |
const char *
gtk_text_get_placeholder_text (GtkText *self
);
Retrieves the text that will be displayed when self
is empty and unfocused
self | a GtkText |
a pointer to the placeholder text as a string. This string points to internally allocated storage in the widget and must not be freed, modified or stored. If no placeholder text has been set, NULL
will be returned.
[nullable][transfer none]
void gtk_text_set_input_purpose (GtkText *self
,GtkInputPurpose purpose
);
Sets the “input-purpose” property which can be used by on-screen keyboards and other input methods to adjust their behaviour.
self | a GtkText | |
purpose | the purpose |
GtkInputPurpose
gtk_text_get_input_purpose (GtkText *self
);
Gets the value of the “input-purpose” property.
self | a GtkText |
void gtk_text_set_input_hints (GtkText *self
,GtkInputHints hints
);
Sets the “input-hints” property, which allows input methods to fine-tune their behaviour.
self | a GtkText | |
hints | the hints |
GtkInputHints
gtk_text_get_input_hints (GtkText *self
);
Gets the value of the “input-hints” property.
self | a GtkText |
void gtk_text_set_attributes (GtkText *self
,PangoAttrList *attrs
);
Sets a PangoAttrList; the attributes in the list are applied to the text.
self | a GtkText | |
attrs | a PangoAttrList or | [nullable] |
PangoAttrList *
gtk_text_get_attributes (GtkText *self
);
Gets the attribute list that was set on the self using gtk_text_set_attributes()
, if any.
self | a GtkText |
the attribute list, or NULL
if none was set.
[transfer none][nullable]
void gtk_text_set_tabs (GtkText *self
,PangoTabArray *tabs
);
Sets a PangoTabArray; the tabstops in the array are applied to the self text.
self | a GtkText | |
tabs | [nullable] |
PangoTabArray *
gtk_text_get_tabs (GtkText *self
);
Gets the tabstops that were set on the self using gtk_text_set_tabs()
, if any.
self | a GtkText |
the tabstops, or NULL
if none was set.
[nullable][transfer none]
gboolean
gtk_text_grab_focus_without_selecting (GtkText *self
);
Causes self
to have keyboard focus.
It behaves like gtk_widget_grab_focus()
, except that it doesn't select the contents of self
. You only want to call this on some special entries which the user usually doesn't want to replace all text in, such as search-as-you-type entries.
self | a GtkText |
TRUE
if focus is now inside self
void gtk_text_set_extra_menu (GtkText *self
,GMenuModel *model
);
Sets a menu model to add when constructing the context menu for self
.
self | a GtkText | |
model | a GMenuModel. | [allow-none] |
GMenuModel *
gtk_text_get_extra_menu (GtkText *self
);
Gets the menu model set with gtk_text_set_extra_menu()
.
self | a GtkText |
the menu model.
[transfer none][nullable]
void gtk_text_set_enable_emoji_completion (GtkText *self
,gboolean enable_emoji_completion
);
Sets whether Emoji completion is enabled. If it is, typing ':', followed by a recognized keyword, will pop up a window with suggested Emojis matching the keyword.
self | a GtkText | |
enable_emoji_completion |
|
gboolean
gtk_text_get_enable_emoji_completion (GtkText *self
);
Returns whether Emoji completion is enabled for this GtkText widget.
self | a GtkText |
TRUE
if Emoji completion is enabled
void gtk_text_set_propagate_text_width (GtkText *self
,gboolean propagate_text_width
);
Sets whether the GtkText should grow and shrink with the content.
self | a GtkText | |
propagate_text_width |
|
gboolean
gtk_text_get_propagate_text_width (GtkText *self
);
Returns whether the GtkText will grow and shrink with the content.
self | a GtkText |
TRUE
if self
will propagate the text width
struct GtkText;
“activates-default”
property“activates-default” gboolean
Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed.
Owner: GtkText
Flags: Read / Write
Default value: FALSE
“attributes”
property“attributes” PangoAttrList *
A list of Pango attributes to apply to the text of the self.
This is mainly useful to change the size or weight of the text.
The PangoAttribute's start_index
and end_index
must refer to the GtkEntryBuffer text, i.e. without the preedit string.
Owner: GtkText
Flags: Read / Write
“buffer”
property“buffer” GtkEntryBuffer *
Text buffer object which actually stores self text.
Owner: GtkText
Flags: Read / Write / Construct
“enable-emoji-completion”
property“enable-emoji-completion” gboolean
Whether to suggest Emoji replacements.
Owner: GtkText
Flags: Read / Write
Default value: FALSE
“extra-menu”
property“extra-menu” GMenuModel *
A menu model whose contents will be appended to the context menu.
Owner: GtkText
Flags: Read / Write
“im-module”
property“im-module” char *
Which IM (input method) module should be used for this self. See GtkIMContext.
Setting this to a non-NULL
value overrides the system-wide IM module setting. See the GtkSettings “gtk-im-module” property.
Owner: GtkText
Flags: Read / Write
Default value: NULL
“input-hints”
property“input-hints” GtkInputHints
Additional hints (beyond “input-purpose”) that allow input methods to fine-tune their behaviour.
Owner: GtkText
Flags: Read / Write
“input-purpose”
property“input-purpose” GtkInputPurpose
The purpose of this text field.
This property can be used by on-screen keyboards and other input methods to adjust their behaviour.
Note that setting the purpose to GTK_INPUT_PURPOSE_PASSWORD
or GTK_INPUT_PURPOSE_PIN
is independent from setting “visibility”.
Owner: GtkText
Flags: Read / Write
Default value: GTK_INPUT_PURPOSE_FREE_FORM
“invisible-char”
property“invisible-char” guint
The character to use when masking self contents (in “password mode”).
Owner: GtkText
Flags: Read / Write
Default value: '*'
“invisible-char-set”
property“invisible-char-set” gboolean
Whether the invisible char has been set for the GtkText.
Owner: GtkText
Flags: Read / Write
Default value: FALSE
“max-length”
property“max-length” int
Maximum number of characters for this self. Zero if no maximum.
Owner: GtkText
Flags: Read / Write
Allowed values: [0,65535]
Default value: 0
“overwrite-mode”
property“overwrite-mode” gboolean
If text is overwritten when typing in the GtkText.
Owner: GtkText
Flags: Read / Write
Default value: FALSE
“placeholder-text”
property“placeholder-text” char *
The text that will be displayed in the GtkText when it is empty and unfocused.
Owner: GtkText
Flags: Read / Write
Default value: NULL
“propagate-text-width”
property“propagate-text-width” gboolean
Whether the entry should grow and shrink with the content.
Owner: GtkText
Flags: Read / Write
Default value: FALSE
“scroll-offset”
property“scroll-offset” int
Number of pixels of the self scrolled off the screen to the left.
Owner: GtkText
Flags: Read
Allowed values: >= 0
Default value: 0
“tabs”
property“tabs” PangoTabArray *
A list of tabstops to apply to the text of the self.
Owner: GtkText
Flags: Read / Write
“truncate-multiline”
property“truncate-multiline” gboolean
When TRUE
, pasted multi-line text is truncated to the first line.
Owner: GtkText
Flags: Read / Write
Default value: FALSE
“visibility”
property“visibility” gboolean
FALSE displays the “invisible char” instead of the actual text (password mode).
Owner: GtkText
Flags: Read / Write
Default value: TRUE
“activate”
signalvoid user_function (GtkText *self, gpointer user_data)
The ::activate signal is emitted when the user hits the Enter key.
The default bindings for this signal are all forms of the Enter key.
self | The widget on which the signal is emitted | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“backspace”
signalvoid user_function (GtkText *self, gpointer user_data)
The ::backspace signal is a keybinding signal which gets emitted when the user asks for it.
The default bindings for this signal are Backspace and Shift-Backspace.
self | the object which received the signal | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“copy-clipboard”
signalvoid user_function (GtkText *self, gpointer user_data)
The ::copy-clipboard signal is a keybinding signal which gets emitted to copy the selection to the clipboard.
The default bindings for this signal are Ctrl-c and Ctrl-Insert.
self | the object which received the signal | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“cut-clipboard”
signalvoid user_function (GtkText *self, gpointer user_data)
The ::cut-clipboard signal is a keybinding signal which gets emitted to cut the selection to the clipboard.
The default bindings for this signal are Ctrl-x and Shift-Delete.
self | the object which received the signal | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“delete-from-cursor”
signalvoid user_function (GtkText *self, GtkDeleteType type, int count, gpointer user_data)
The ::delete-from-cursor signal is a keybinding signal which gets emitted when the user initiates a text deletion.
If the type
is GTK_DELETE_CHARS
, GTK deletes the selection if there is one, otherwise it deletes the requested number of characters.
The default bindings for this signal are Delete for deleting a character and Ctrl-Delete for deleting a word.
self | the object which received the signal | |
type | the granularity of the deletion, as a GtkDeleteType | |
count | the number of | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“insert-at-cursor”
signalvoid user_function (GtkText *self, char *string, gpointer user_data)
The ::insert-at-cursor signal is a keybinding signal which gets emitted when the user initiates the insertion of a fixed string at the cursor.
This signal has no default bindings.
self | the object which received the signal | |
string | the string to insert | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“insert-emoji”
signalvoid user_function (GtkText *self, gpointer user_data)
The ::insert-emoji signal is a keybinding signal which gets emitted to present the Emoji chooser for the self
.
The default bindings for this signal are Ctrl-. and Ctrl-;
self | the object which received the signal | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“move-cursor”
signalvoid user_function (GtkText *self, GtkMovementStep step, int count, gboolean extend, gpointer user_data)
The ::move-cursor signal is a keybinding signal which gets emitted when the user initiates a cursor movement. If the cursor is not visible in self
, this signal causes the viewport to be moved instead.
Applications should not connect to it, but may emit it with g_signal_emit_by_name()
if they need to control the cursor programmatically.
The default bindings for this signal come in two variants, the variant with the Shift modifier extends the selection, the variant without the Shift modifier does not. There are too many key combinations to list them all here.
Arrow keys move by individual characters/lines
Ctrl-arrow key combinations move by words/paragraphs
Home/End keys move to the ends of the buffer
self | the object which received the signal | |
step | the granularity of the move, as a GtkMovementStep | |
count | the number of | |
extend |
| |
user_data | user data set when the signal handler was connected. |
Flags: Action
“paste-clipboard”
signalvoid user_function (GtkText *self, gpointer user_data)
The ::paste-clipboard signal is a keybinding signal which gets emitted to paste the contents of the clipboard into the text view.
The default bindings for this signal are Ctrl-v and Shift-Insert.
self | the object which received the signal | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“preedit-changed”
signalvoid user_function (GtkText *self, char *preedit, gpointer user_data)
If an input method is used, the typed text will not immediately be committed to the buffer. So if you are interested in the text, connect to this signal.
self | the object which received the signal | |
preedit | the current preedit string | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“toggle-overwrite”
signalvoid user_function (GtkText *self, gpointer user_data)
The ::toggle-overwrite signal is a keybinding signal which gets emitted to toggle the overwrite mode of the self.
The default bindings for this signal is Insert.
self | the object which received the signal | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“menu.popup”
actionOpens the context menu.
“text.redo”
actionRedoes the last change to the contents.
“text.undo”
actionUndoes the last change to the contents.
“misc.toggle-visibility”
actionToggles the “visibility” property.
“misc.insert-emoji”
actionOpens the Emoji chooser.
“selection.select-all”
actionSelects all of the widgets content.
“selection.delete”
actionDeletes the current selection.
“clipboard.paste”
actionInserts the contents of the clipboard into the widget.
“clipboard.copy”
actionCopies the contents to the clipboard.
“clipboard.cut”
actionCopies the contents to the clipboard and deletes it from the widget.
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk4/4.0/GtkText.html