【问题标题】:Assign click event to a wxPanel instance将点击事件分配给 wxPanel 实例
【发布时间】:2013-11-09 23:12:07
【问题描述】:

我有一个 wxPanel 类。我需要该类的每个实例都处理一个单击事件。在 wxWidgets 中这可能吗?到目前为止,我总是不得不使用窗口 ID 将事件分配给对象(例如按钮)。
但是这个 wxPanel 即将在屏幕上以乘法出现,所以我需要避免使用窗口 ID。

班级:

面板.h

class UVStatusPanel : public wxPanel
{

public:
    UVStatusPanel(wxFrame* parent, int pos);

    void paintEvent(wxPaintEvent& evt);
    void paintNow();

    //THIS is expected to be the event function
    void onClick(wxCommandEvent& WXUNUSED(event));

    bool State(bool state);
    bool State();

    DECLARE_EVENT_TABLE()
private:
    bool painting;
    bool state;
    void render(wxDC &dc);
};

panel.cpp

/**The constructor*/
UVStatusPanel::UVStatusPanel(wxFrame* parent, int pos) :
wxPanel(parent)
{
 /** some align and draw rect code was there**/
 //My two attepmts to assign the click event to the panel
 Connect(this->m_windowId, wxEVT_COMMAND_LEFT_CLICK, 
          wxCommandEventHandler(UVStatusPanel::onClick));
 //EVT_COMMAND_LEFT_CLICK(this->m_windowId,UVStatusPanel::onFocus);
}

目前已注册 noc 点击。谁能解释一下 wxWidgets 中的点击事件是如何工作的?

【问题讨论】:

    标签: c++ events wxwidgets


    【解决方案1】:

    wxEVT_COMMAND_LEFT_CLICK 不是由wxPanel 生成的(老实说,几乎也不是由其他任何东西生成的),您要查找的事件称为wxEVT_LEFT_UP,它是wxMouseEvent,而不是wxCommandEvent

    此外,不建议在您的示例中同时使用事件表和Connect()。它确实有效,但有令人困惑的风险,只需选择一个并坚持使用它(最好是Connect(),或者,如果你使用 2.9+,Bind())。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      相关资源
      最近更新 更多