Fixing first N characters of Entry and set them as non-editable

Hi guys,

Is there a way to set first let’s say 5 characters of an Entry widget and set them as non-editable as in not selectable or editable ?

Thanks,

Look into GtkTextTag:editable, and setting that to FALSE on the region in your GtkTextBuffer that should be locked.

1 Like

Not for GtkEntry; you also did not specify whether you’re using GTK4 or GTK3.

1 Like

You could try to connect to delete signal and cancel deletion of letters. This is for gtk3

Gtk.Editable::delete-text

This signal is emitted when text is deleted from the widget by the user. The default handler for this signal will normally be responsible for deleting the text, so by connecting to this signal and then stopping the signal with g_signal_stop_emission(), it is possible to modify the range of deleted text, or prevent it from being deleted entirely. The start_pos and end_pos parameters are interpreted as for gtk_editable_delete_text().

GTK4 have same signal Editable::delete-text

2 Likes

It’s GTK3, I figured out the issue thanks to your comments and guides! :smiley:

1 Like

What solution did you pick in the end? In case anyone finds this searching later and it can help them :wink:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.