wxWidgets 2.9.1 - 使用多个 wxStaticBox 时出现键盘导航问题
wxWidgets 2.9.1 文档推荐了创建静态框的新方法 - 我们应该创建所有staticbox 内的控件作为其子项。
但是,当对话框/面板中有多个静态框时,键盘导航就会出现问题。无法在放置在不同静态框中的控件之间移动光标。方法 wxWindow::MoveAfterInTabOrder() 和 wxWindow::MoveBeforeInTabOrder 在这里没有用,因为它们只适用于同一父窗口的兄弟窗口。
此示例代码创建带有两个静态框的对话框,每个静态框都是两个编辑控件的父控件。我应该怎么做才能使用 Tab 键从编辑控件 #2 导航到编辑控件 #3?
void CreateTestDialog(wxWindow* parent)
{
wxWindowID id = 10010;
long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL;
wxDialog dlg;
dlg.SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
if (dlg.Create(parent, id, wxT("Tab Order Test"), wxDefaultPosition, wxDefaultSize, style))
{
wxBoxSizer* sizer1 = new wxBoxSizer(wxVERTICAL);
dlg.SetSizer(sizer1);
wxStaticBox* staticbox1 = new wxStaticBox(&dlg, wxID_ANY, _("Static1"), wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
wxStaticBoxSizer* sizer2 = new wxStaticBoxSizer(staticbox1, wxVERTICAL);
sizer1->Add(sizer2, 0, wxGROW|wxALL, 5);
wxTextCtrl* m_ctl_text1 = new wxTextCtrl( staticbox1, 10011 );
sizer2->Add(m_ctl_text1, 0, wxGROW|wxALL, 5);
wxTextCtrl* m_ctl_text2 = new wxTextCtrl( staticbox1, 10012);
sizer2->Add(m_ctl_text2, 0, wxGROW|wxALL, 5);
wxStaticBox* staticbox2 = new wxStaticBox(&dlg, wxID_ANY, _("Static2"), wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
wxStaticBoxSizer* sizer3 = new wxStaticBoxSizer(staticbox2, wxVERTICAL);
sizer1->Add(sizer3, 0, wxGROW|wxALL, 5);
wxTextCtrl* m_ctl_text3 = new wxTextCtrl( staticbox2, 10013);
sizer3->Add(m_ctl_text3, 0, wxGROW|wxALL, 5);
wxTextCtrl* m_ctl_text4 = new wxTextCtrl( staticbox2, 10014);
sizer3->Add(m_ctl_text4, 0, wxGROW|wxALL, 5);
dlg.ShowModal();
}
}
请不要建议我使用创建控件的旧方法(作为静态框的兄弟)。创建静态框的新方法解决了令人讨厌的显示故障 - 这是我正在尝试解决的真正问题解决。
谢谢瓦塞克
wxWidgets 2.9.1 documentation recommends the new way of creating staticboxes - we should create all controls inside the staticbox as its children.
However, there's a problem with keyboard navigation when you have more than one staticbox in your dialog/panel. There is no way to move cursor between controls placed in different staticboxes. Methods wxWindow::MoveAfterInTabOrder() and wxWindow::MoveBeforeInTabOrder are useless here, since they work only with siblings of the same parent window.
This sample code creates dialog with two staticboxes, each of them being the parent of the two edit controls. What should I do to be able to navigate with Tab key from edit control #2 to edit control #3?
void CreateTestDialog(wxWindow* parent)
{
wxWindowID id = 10010;
long style = wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL;
wxDialog dlg;
dlg.SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
if (dlg.Create(parent, id, wxT("Tab Order Test"), wxDefaultPosition, wxDefaultSize, style))
{
wxBoxSizer* sizer1 = new wxBoxSizer(wxVERTICAL);
dlg.SetSizer(sizer1);
wxStaticBox* staticbox1 = new wxStaticBox(&dlg, wxID_ANY, _("Static1"), wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
wxStaticBoxSizer* sizer2 = new wxStaticBoxSizer(staticbox1, wxVERTICAL);
sizer1->Add(sizer2, 0, wxGROW|wxALL, 5);
wxTextCtrl* m_ctl_text1 = new wxTextCtrl( staticbox1, 10011 );
sizer2->Add(m_ctl_text1, 0, wxGROW|wxALL, 5);
wxTextCtrl* m_ctl_text2 = new wxTextCtrl( staticbox1, 10012);
sizer2->Add(m_ctl_text2, 0, wxGROW|wxALL, 5);
wxStaticBox* staticbox2 = new wxStaticBox(&dlg, wxID_ANY, _("Static2"), wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
wxStaticBoxSizer* sizer3 = new wxStaticBoxSizer(staticbox2, wxVERTICAL);
sizer1->Add(sizer3, 0, wxGROW|wxALL, 5);
wxTextCtrl* m_ctl_text3 = new wxTextCtrl( staticbox2, 10013);
sizer3->Add(m_ctl_text3, 0, wxGROW|wxALL, 5);
wxTextCtrl* m_ctl_text4 = new wxTextCtrl( staticbox2, 10014);
sizer3->Add(m_ctl_text4, 0, wxGROW|wxALL, 5);
dlg.ShowModal();
}
}
Please don't advice me to use the old way of creating controls (as siblings of the staticboxes). The new way of creating staticboxes solves the nasty display glitch - that's the real problem I'm trying to solve.
Thanks
Wacek
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题终于在wxWidgets 2.9.5的预发布版本中得到解决。
更多信息可以在相应的票务页面上找到
我确实回答了我自己的问题,因为有没有其他答案。也许这对其未来其他人有用。
Problem was finally solved in the pre-release version of wxWidgets 2.9.5.
More information can be found on the corresponding ticket page
I did answer to my own question, because there were no other answers. Maybe this will be useful for someone else in the future.