How to select text in GtkEntry

I have a dialog box with GtkEntry. I want to select all the text in the record immediately after the dialog box becomes visible to the user. I tried this, but its not working, I don't see a choice:

static void OnEntryShow(GtkWidget *entry, gpointer user_data)
{
     gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
}
...
gtk_entry_set_text(GTK_ENTRY(myEntry), "text");
g_signal_connect(myEntry, "show", G_CALLBACK(OnEntryShow), NULL);
if (gtk_dialog_run(GTK_DIALOG(myDialog)) == GTK_RESPONSE_OK)
...

How to select text in GtkEntry after GtkDialog becomes visible?

+3
source share
2 answers

Perhaps you want GtkEntry to capture focus?

Try the following:

gtk_widget_grab_focus (entry);

where entryis in this case a pointer to your GtkEntry widget.

Function documentation can be found here .

+3
source

You must use the function registered here .

text_entry.select_region(0,2)selects the first two characters, and (0, -1)selects all the text.

+2
source

All Articles