GtkEntry and validating user input

In many places, I get user input using a GtkEntry (well, Gtk::Entry,
since I'm using Gtkmm).  I'd like to validate the input and, if the
input is invalid, set the background colour of the Entry to red and
restore focus to the Entry, if needed.

I can do this by connecting to the "changed" signal of the
GtkEditable.  This works just fine when I want to filter the user
input (I just read the text in the Editable, strip out any unwanted
bits and set it with the new text).  However, I really only want to do
the validation (and highlighting in red) when the user has finished
typing, either when they focus out or press Enter.

When I tried this validation in the "activate" signal, this didn't
work: it activated the default widget, which was the OK button of the
dialog.  I couldn't prevent the dialog returning RESPONSE_OK, even
when there was an error.  How can I prevent this happening?  Should
returning false in the "focus-out-event" signal handler stop this?


Roger Leigh

                Printing on GNU/Linux?
                GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]