Re: How to set a button to be activated when i press the enter key
- From: "David Necas (Yeti)" <yeti physics muni cz>
- To: Suresh Stephen <stephenwalter_2k2 yahoo com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: How to set a button to be activated when i press the enter key
- Date: Sat, 31 Dec 2005 12:55:29 +0100
On Sat, Dec 31, 2005 at 03:39:59AM -0800, Suresh Stephen wrote:
Just wanted to know one thing , for example consider i have a text entry and two buttons ok and
cancel . Wat i want to perform is after adding some data to the entry i just want to press enter so that
the ok button is pressed, if any one knows a way to solve this i will be very thankful for that.
Most likely you want to use gtk_entry_set_activates_default().
============================================================================
#include <gtk/gtk.h>
int
main(int argc, char *argv[])
{
GtkWidget *dialog, *entry;
gint response;
gtk_init(&argc, &argv);
dialog = gtk_dialog_new_with_buttons("Entry Activate", NULL, 0,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
entry = gtk_entry_new();
gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entry);
gtk_widget_show_all(dialog);
response = gtk_dialog_run(GTK_DIALOG(dialog));
g_print("Response: %d\nText: %s\n",
response, gtk_entry_get_text(GTK_ENTRY(entry)));
gtk_widget_destroy(dialog);
return 0;
}
============================================================================
Otherwise you can connect to "activate" signal of the entry
and perform arbitrary user-confusing action in the callback.
Yeti
--
That's enough.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]