如何从FLTK中的Fl_Button选项卡移开



我有一个自定义类CustomButton,它扩展了Fl_Button。在我的屏幕上有一堆Fl_InputCustomButton小部件,我希望能够使用选项卡键在它们之间导航。输入字段之间的制表很好,但一旦CustomButton获得焦点,我似乎就无法摆脱它

这是我的手柄功能

int CustomButton::handle ( int event )
{
int is_event_handled = 0;
switch (event)
{
case FL_KEYBOARD:
// If the keypress was enter, toggle the button on/off
if (Fl::event_key() == FL_Enter || Fl::event_key() == FL_KP_Enter)
{
// Do stuff...
}
is_event_handled = 1;
break;
case FL_FOCUS:
case FL_UNFOCUS:
// The default Fl_Button handling does not allow Focus/Unfocus
// for the button so mark the even as handled to skip the Fl_Button processing
is_event_handled = 1;
break;
default:
is_event_handled = 0;
break;
}
if ( is_event_handled == 1 ) return 1;
return Fl_Round_Button::handle ( event );
}

我使用的是fltk 1.1.10。

要获得一个演示如何控制焦点的非常简单、最小的示例,请查看navigation.cxx测试文件。

也许你的小部件确实得到了焦点(用Fl::focus((检查一下(,但它没有显示出来(你需要处理Fl_focus和/或Fl_UNFOCUS事件(?

我的问题是CustomButton::handle()FL_KEYBOARD事件后返回1,而实际上没有使用tab键。

is_event_handled = 1移动到if语句中只允许我使用FL_Enter按键,并允许其他小部件(即控制导航的Fl_Group(使用任何其他按键。

或者去掉if,用之类的东西代替

switch(Fl::event_key())
{
case FL_Enter:
case FL_KP_Enter:
// Do stuff
is_event_handled = 1;
break;
default:
is_event_handled = 0;
break;
}

最新更新