Question

i have dialog window with GtkEntry. I want to select all text in entry right after dialog window becomes visible to user. I tried this, but its not working, i see no selection:

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 can i select text in GtkEntry after GtkDialog becomes visible?

Was it helpful?

Solution

Perhaps you want the GtkEntry to grab focus?

Try this:

gtk_widget_grab_focus (entry);

where entry is in this case the pointer to your GtkEntry widget.

The documentation of the function can be found here.

OTHER TIPS

You should use the function documented here.

text_entry.select_region(0,2) will select the first two characters, while (0, -1) will select the entire text.

Here's a solution I've used for gtkmm using the get_iter_at_offset and select_range functions.

Gtk::TextIter match_start = m_textBuffer->get_iter_at_offset(0);
Gtk::TextIter match_end = m_textBuffer->get_iter_at_offset(-1); // -1 to select all
m_textBuffer->select_range(match_start,match_end);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top