将单击事件分配给 wxPanel 实例
Assign click event to a wxPanel instance
我有一个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);
};
面板.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 中是如何工作的?
wxEVT_COMMAND_LEFT_CLICK
不是由wxPanel
生成的(老实说,也不是由其他任何东西生成的),您正在寻找的事件称为wxEVT_LEFT_UP
,它是一个wxMouseEvent
,而不是wxCommandEvent
。
此外,不建议在示例中同时使用事件表和Connect()
。它确实有效,但可能会令人困惑,只需选择一个并坚持使用它(最好是Connect()
或者,如果您使用 2.9+,Bind()
)。
相关文章:
- 从C++实例化QML
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 如何在c++中为模板函数实例创建快捷方式
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 设计一个只能由特定类实例化的类(如果可能的话,通过make_unique)
- 如何创建一个空的全局类并在启动时实例化它
- 无法创建抽象类的实例
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 我收到以下错误:抛出'std::bad_alloc'实例后终止调用
- 建议在运行时将带有类实例的列表从c++导入qml
- 约束和显式模板实例化
- 通过实例理解std::move及其目的
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 有没有一种"cleaner"的方法可以在指向基的指针向量中找到派生类的第一个实例?
- 正在生成未知类实例
- 从DLL中删除类的实例
- 在std::vector上存储带有模板的类实例
- 将单击事件分配给 wxPanel 实例