如何从FLTK中的Fl_Button移开?

问题描述 投票:1回答:1

我有一个自定义类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。

c++ fltk
1个回答
0
投票

有关演示如何控制焦点的非常简单的最小示例,请检查navigation.cxx测试文件。

也许您的窗口小部件确实获得了焦点(可通过Fl :: focus()进行检查),但并没有显示出来(您需要处理FL_FOCUS和/或FL_UNFOCUS事件)?

© www.soinside.com 2019 - 2024. All rights reserved.