wxWidgets 动态复选框列表提示

wxWidgets tips for dynamic list of checkboxes

我正在使用 wxWidgets 并尝试显示设备动态列表(复选框)的工具提示:

for (DeviceHolder devH : *devices) {
    uint64_t addr = devH.bleAddress;
    wxCheckBox* cbox = new wxCheckBox(panel, wxID_ANY, AddrToString(addr));
    checkboxsizer->Add(cbox, 0, wxLEFT, 20);
    Connect(cbox->GetId(), wxEVT_MOVE, wxMoveEventHandler(DeviceListDialog::onMove));
    boxes.push_back(std::pair(cbox, addr));
    std::stringstream stream;
    stream << "Device name: " + devH.deviceName;
    this->tips->insert(std::pair< wxWindowID, std::string>(cbox->GetId(), stream.str()));
}



void DeviceListDialog::onMove(wxMoveEvent& event) {
    std::cout << ".";
    std::string msg = this->tips->find(event.GetId())->second;
    wxRichToolTip tip(wxT("INFO"), msg);
    tip.ShowFor(this);
}

没有任何作用,功能DeviceListDialog::onMove没有作用,没有提示出现。告诉我可以做什么?

鼠标事件不会向上传播,因此无论您尝试将事件连接到行中什么

Connect(cbox->GetId(), wxEVT_MOVE, wxMoveEventHandler(DeviceListDialog::onMove));

永远不会收到该事件。顺便说一下,出于各种原因,您应该使用 Bind 而不是 connect。


相反,您应该使用复选框本身的 Bind 方法。这样的事情应该有效:

cbox->Bind(wxEVT_MOTION, &DeviceListDialog::onMove, this);

我假设此代码出现在 DeviceListDialog 的构造函数中。如果代码在其他地方 运行,请将 this 替换为指向正在构造的 DeviceListDialog 的指针。