5
votes

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?

3
Your method should work. This may sound a little obvious but does the entry have text set? How have you set the text? - another.anon.coward
Is the signal handler actually getting called? Maybe the widget is already shown by the time you connect the signal. - ptomato

3 Answers

4
votes

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.

4
votes

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.

0
votes

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);