Entry Widget Tab Out Behavior

I am having a problem with the behavior of the tab key when trying to
reselect text of a just-tab-out-of entry widget.

So here is what I want to happen.  A user inputs a value in to tboxB.
If that input is invalid, they are issued an error message about the
problem and after confirming the error message, tboxB is refocused and
all the text is selected.

So here is what happens.  The user inputs a bad value, the user hits
the "tab" key, the error message displays, the user closes the error
message, focus is given to tboxB and all the text of the next entry
widget is selected instead of selecting tboxB's text.

If the user unfocuses the entry widget by clicking the cursor in to
another entry widget then everything works as planned.

I feel like the default action of "tab"ing through entry widgets
(selected the text of the newly focused entry widget) overrides my
call to select all text in tboxB.

Simplified code:

Gtk::Entry* tboxA;
Gtk::Entry* tboxB;

CustomPanel::CustomPanel() {
        sigc::bind(sigc::mem_fun(*this, &CustomPanel::onChange),
        sigc::bind(sigc::mem_fun(*this, &CustomPanel::focusOut),

void CustomPanel::onChange(std::string name) {
    if(name == "tboxA") {
    } else if (name == "tboxB") {
        // nothing right now

bool CustomPanel::focusOut(GdkEventFocus* event, std::string name) {
    if(name == "tboxA") {
    } else if (name == "tboxB") {
        if (checkInput(tboxB->get_text())) {
            // all is good
        } else {
            // alert to problem
            tboxB->select_region(0, -1); // Select the whole thing
    return false;

What is the best way to get what I want?

Thanks in advance,
Dustin Moore

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