问题
I am using a wxWidget
. I have panel
with 4 buttons and using wxGridSizer
to put them in grid. When i go to the rightmost cell of the row and press Right key
, focus remains on the same widget. Can i set some property where Right/Left
keys at corner works as tab and shift-tab.
What i want is that user should be able to circle
through the 4 buttons by just pressing left and right keys. I want to use up/down keys for other purpose.
Here is the code if it helps :
#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:
There is no built-in support for this, but you can catch WXK_RIGHT
and WXK_LEFT
yourself in your wxEVT_CHAR
handler and do whatever you want there. You can look at wxGrid::DoGridProcessTab()
for an example of what you might want to do, e.g. notice the helper MoveCursor{Left,Right}()
and GoToCell()
methods used there.
来源:https://stackoverflow.com/questions/46502297/wxgridsizer-wxpanel-make-left-right-navigation-key-behave-like-shift-tab-tab