无法使用鼠标单击来选中wxTreeListCtrl项的复选框

Unable to check checkboxes for wxTreeListCtrl items using mouse click

本文关键字:wxTreeListCtrl 复选框 鼠标 单击      更新时间:2023-10-16

我使用wxTreeListCtrl与wxTL_CHECKBOX样式,但由于某种原因,我不能使用鼠标单击检查复选框,虽然我可以通过按空格来做到这一点。这是正常的,还是我错过了什么?

我代码:

// .h file
#include <wx/wx.h>
#include <wx/treelist.h>
class MyApp: public wxApp
{
public:
    virtual bool OnInit();
};
class MyFrame: public wxFrame
{
public:
    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
private:
    void OnTreeLeftDown (wxMouseEvent& evt);
private:
    enum 
    {
        TreeListId = 1
    };
    wxTreeListCtrl*  m_treeList;
    wxDECLARE_EVENT_TABLE();
};
// .cpp file
wxBEGIN_EVENT_TABLE (MyFrame, wxFrame)
wxEND_EVENT_TABLE()
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame ("Hello World", wxPoint(50, 50), wxSize(600, 400));
    frame->Show (true);
    return true;
}
MyFrame::MyFrame (const wxString& title, const wxPoint& pos, const wxSize& size)
        : wxFrame (NULL, wxID_ANY, title, pos, size)
{
    m_treeList = new wxTreeListCtrl (this, TreeListId, wxPoint (10, 10), wxSize(600, 400), wxTL_CHECKBOX);
    m_treeList->AppendColumn (L"Item Name");
    m_treeList->AppendItem (m_treeList->GetRootItem(), L"Test");
    m_treeList->AppendItem (m_treeList->GetRootItem(), L"Another one");
    CenterOnScreen ();
}

有人在wxWidgets论坛上指出这是3.0.0中的一个bug这里是bug url http://trac.wxwidgets.org/ticket/15731