Re: confused about keyboard focus

On Dec 30, 2005, at 4:08 PM, Torsten Schoenfeld wrote:

On Fri, 2005-12-30 at 15:11 -0500, Travis J.I. Corcoran wrote:

        $entry2->has_focus(TRUE); # <---- IMPORTANT LINE

has_focus just tells the entry that it's supposed to have focus now and
should thus draw the blinking cursor, etc. that you see.

Specifically, this just sets a flag in the widget, without doing anything else. This is something intended for use by widget implementations, not by application code.

Here are three ways that work:

  Glib::Idle->add (sub { $entry2->grab_focus; 0; });
  Glib::Idle->add (sub { $window->set_focus ($entry2); 0; });

If i recall correctly, the purpose of using the idle here is to defer the focus grab until after the window is on the screen, since the window will try to override the focus as it goes onscreen. I've not tested this, but i believe an alternative to using an idle here is to perform this operation in an "after" handler for the window's realize or map signals.

  $vbox->set_focus_child ($entry2);

Meg: Brian! Chris picked his nose and keeps trying to touch me with his finger! Chris: What good is mining nose gold if I can't share it with the townspeople?
   -- Family Guy

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