子窗口hotkey 无效 (linux platform wx3.0)

这是wxWidgets论坛的中文版本。在这里,您可以用您的母语汉语讨论上面任一子论坛所涉及的所有关于wxWidgets的话题。欢迎大家参与到对有价值的帖子的中英互译工作中来!
jerome_mao
Earned a small fee
Earned a small fee
Posts: 12
Joined: Mon Jul 18, 2016 6:02 am

子窗口hotkey 无效 (linux platform wx3.0)

Postby jerome_mao » Thu Jul 21, 2016 3:32 am

最近将wx库从2.8升级到3.0.2 遇到一个HotKey的问题。子窗口的menu的快捷键失效了,与此相关的是子窗口里的一个panel 定义了keyEvent事件。
,focus在此panel上,敲快捷键,menu的快捷键不起效用,keyevent事件进入了。但windows上是好的,wx2.8 也没有问题,就linux上无效(redhat6.3 centos5.6(gnome))。有谁遇到这问题的么 ,该如何解决,请帮忙看下,谢谢
下面是一个简单的测试例子,子窗口的ID_EXITSUBWIN和ID_EXITSUBWIN的menu事件没有触发。

Code: Select all

#include <wx/wx.h>


#define ID_OPENSUBWIN 1000
#define ID_EXITWIN 1001
#define ID_TIPWARNING 1002
#define ID_EXITSUBWIN 1003
class CSubPanel : public wxPanel
{
public:
   CSubPanel(wxWindow *parent);

   void OnKeyDown(wxKeyEvent &event);

   DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(CSubPanel, wxPanel)
EVT_KEY_DOWN(CSubPanel::OnKeyDown)
END_EVENT_TABLE()

CSubPanel::CSubPanel(wxWindow *parent) : wxPanel(parent, -1)
{

}

void CSubPanel::OnKeyDown(wxKeyEvent &event)
{
   int keycode = event.GetKeyCode();
   switch (keycode){
   case 'O':
      wxMessageBox("key event");
      break;
   default:
      break;
   }

   event.Skip();
}

class CSubWindow : public wxFrame
{
public:
   CSubWindow(wxWindow *parent);

   void OnMenu(wxCommandEvent& event);
   void OnClose(wxCloseEvent& event);

   DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(CSubWindow, wxFrame)
EVT_CLOSE(CSubWindow::OnClose)
EVT_MENU(ID_TIPWARNING, CSubWindow::OnMenu)
EVT_MENU(ID_EXITWIN, CSubWindow::OnMenu)
END_EVENT_TABLE()
CSubWindow::CSubWindow(wxWindow *parent) : wxFrame(parent, -1, wxT("SubWindow"), wxDefaultPosition, wxSize(600, 600))
{
   wxMenuBar *menubar = new wxMenuBar();
   wxMenu* fileMenu = new wxMenu;
   fileMenu->Append(ID_TIPWARNING, wxT("&Warning dlg\tO"));
   fileMenu->AppendSeparator();
   fileMenu->Append(ID_EXITSUBWIN, wxT("E&xit\tCtrl+Q"));
   menubar->Append(fileMenu, wxT("Window"));
   SetMenuBar(menubar);
   CSubPanel *panel = new CSubPanel(this);

   wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
   mainSizer->Add(panel, 1, wxEXPAND);

   SetSizer(mainSizer);
   SetAutoLayout(true);
}

void CSubWindow::OnMenu(wxCommandEvent& event)
{
   if (event.GetId() == ID_TIPWARNING)
   {
      wxMessageDialog dlg(this, "Tip Window");
      dlg.ShowModal();
   }
   else if (event.GetId() == ID_EXITSUBWIN)
   {
      this->Destroy();
   }

   event.Skip();
}

void CSubWindow::OnClose(wxCloseEvent& event)
{
   Destroy();
}

class CTestMainWindow :public wxFrame
{
public:
   CTestMainWindow(wxWindow* parent);
   void OnClose(wxCloseEvent& event);
   void OnMenu(wxCommandEvent& event);

   DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(CTestMainWindow, wxFrame)
EVT_CLOSE(CTestMainWindow::OnClose)
EVT_MENU(ID_OPENSUBWIN,CTestMainWindow::OnMenu)
EVT_MENU(ID_EXITSUBWIN, CTestMainWindow::OnMenu)
EVT_MENU(ID_TIPWARNING, CTestMainWindow::OnMenu)
END_EVENT_TABLE()

CTestMainWindow::CTestMainWindow(wxWindow* parent) : wxFrame(parent, -1, wxT("MainWindow"), wxDefaultPosition, wxSize(720,680))
{
   wxMenuBar *menubar = new wxMenuBar();
   wxMenu* fileMenu = new wxMenu;
   fileMenu->Append(ID_OPENSUBWIN, wxT("&Open..\tCtrl+O"));
   fileMenu->AppendSeparator();
   fileMenu->Append(ID_EXITWIN, wxT("E&xit\tCtrl+X"));
   menubar->Append(fileMenu, wxT("Window"));

   SetMenuBar(menubar);
}
void CTestMainWindow::OnClose(wxCloseEvent& event)
{
   Destroy();
}
void CTestMainWindow::OnMenu(wxCommandEvent& event)
{
   int evtid = event.GetId();
   if (evtid == ID_OPENSUBWIN)
   {
      CSubWindow* subwindow = new CSubWindow(this);
      subwindow->Show();
   }
   else if (evtid == ID_EXITWIN)
   {
      Destroy();
   }
   event.Skip();
}
class CTestApp : public wxApp
{
public:
   CTestApp();
   bool   OnInit(void);
   int   OnExit(void);

protected:
   
   CTestMainWindow *frame;

};
IMPLEMENT_APP(CTestApp)
CTestApp::CTestApp()
{

}

bool CTestApp::OnInit()
{
   frame = new CTestMainWindow(NULL);
   frame->CentreOnScreen(wxBOTH);
   frame->Show(TRUE);

   SetTopWindow(frame);

   return true;
}
int CTestApp::OnExit(void)
{
   return wxApp::OnExit();
}



Return to “wxWidgets Development (Chinese)”

Who is online

Users browsing this forum: No registered users and 2 guests