wxGridSizer / wxPanel:使左/右导航键的行为类似于shift-tab / tab

时间:2017-09-30 11:32:18

标签: c++ wxwidgets

我正在使用wxWidget。我有panel个带有4个按钮并使用wxGridSizer将它们放入网格中。当我转到行的最右边的单元格并按Right key时,焦点仍然在同一个小部件上。我可以设置一些属性,其中角落处的Right/Left键作为制表符和shift-tab。

我想要的是用户只需按左右键就能通过4个按钮circle。我想将up / down键用于其他目的。

如果有帮助,这是代码:

#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/sizer.h>
#include <wx/string.h>

#include <iostream>
#include <cassert>

class ReachItFrame : public wxFrame
{
public:
  ReachItFrame(const wxString& title) : wxFrame()
  {
    Create(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150));
  }
};

class MyApp : public wxApp
{
public:
  bool OnInit()
  {
    ReachItFrame *reachIt = new ReachItFrame(wxT("ReachIt"));
    reachIt->Show(true);
    assert(reachIt->SetTransparent(150));
    assert(reachIt->ShowFullScreen(true, wxFULLSCREEN_ALL));

    wxPanel *panel = new wxPanel(reachIt);
    wxGridSizer *sizer = new wxGridSizer(2, 2, 0, 0);

    wxButton *button1 = new wxButton(panel, wxID_ANY, wxString::FromAscii("1"));
    sizer->Add(button1, wxSizerFlags().Expand());

    wxButton *button2 = new wxButton(panel, wxID_ANY, wxString::FromAscii("2"));
    sizer->Add(button2, wxSizerFlags().Expand());

    wxButton *button3 = new wxButton(panel, wxID_ANY, wxString::FromAscii("3"));
    sizer->Add(button3, wxSizerFlags().Expand());

    wxButton *button4 = new wxButton(panel, wxID_ANY, wxString::FromAscii("4"));
    button4->MoveBeforeInTabOrder(button3);
    sizer->Add(button4, wxSizerFlags().Expand());

    panel->SetSizerAndFit(sizer);

    return true;
  }
};

wxIMPLEMENT_APP(MyApp);

1 个答案:

答案 0 :(得分:1)

此处没有内置支持,但您可以在WXK_RIGHT处理程序中自己捕获WXK_LEFTwxEVT_CHAR,并在那里执行任何操作。您可以查看wxGrid::DoGridProcessTab()以获取您可能要执行的操作的示例,例如注意那里使用的助手MoveCursor{Left,Right}()GoToCell()方法。