问题描述
我使用“wxPopupTransientwindow”创建了一个弹出窗口并添加了一些文本和一个按钮。现在我只想在单击此特定按钮时销毁此弹出窗口。现在,如果点击它外面的任何地方,Popup 将被破坏。 这是我迄今为止尝试过的。
SimpleTransientPopup::SimpleTransientPopup(wxWindow *parent,bool scrolled) : wxPopupTransientwindow(parent,wxFRAME_SHAPED)
{
m_bGotItClick = false;
m_panel = new wxScrolledWindow(this,-1,wxDefaultPosition,wxDefaultSize);
m_panel->SetBackgroundColour(*wxYELLOW);
wxStaticText *text = new wxStaticText( m_panel,wxID_ANY,"This panel will guide you stepwise through the workflow\n");
wxPanel *pBottomPanel = new wxPanel(m_panel,-1);
m_button = new wxButton(pBottomPanel,Minimal_PopupButton,"Got it!",wxDefaultSize);
m_link = new wxHyperlinkCtrl(pBottomPanel,Minimal_PopupLink,_("Hide these tips"),_(""),wxDefaultSize,wxHL_ALIGN_LEFT);
m_link->SetFont(wxFont(10,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_ITALIC,wxFONTWEIGHT_norMAL,true));
m_link->SetnormalColour(*wxLIGHT_GREY);
m_link->SetForegroundColour(*wxLIGHT_GREY);
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer *bottomSizer = new wxBoxSizer(wxHORIZONTAL);
bottomSizer->Add(m_link,wxALL,20);
bottomSizer->AddStretchSpacer();
bottomSizer->Add(m_button,20);
pBottomPanel->SetAutoLayout(true);
pBottomPanel->SetSizer(bottomSizer);
bottomSizer->SetSizeHints(pBottomPanel);
bottomSizer->Fit(pBottomPanel);
topSizer->Add(text,wxEXPAND | wxLEFT | wxRIGHT | wxTOP,20);
topSizer->Add(pBottomPanel,wxEXPAND);
m_panel->SetSizer( topSizer );
// Use the fitting size for the panel if we don't need scrollbars.
topSizer->Fit(m_panel);
SetClientSize(m_panel->GetSize());
wxTipKind tipKind = wxTipKind_Auto;
const int offsetY = SetTipShapeAndSize(tipKind,GetBestSize());
if (offsetY > 0)
{
// Offset our contents by the tip height to make it appear in the
// main rectangle.
topSizer->Prependspacer(offsetY);
}
m_panel->Fit();
}
void SimpleTransientPopup::Ondismiss()
{
if (m_bGotItClick) {
wxLogMessage("%p SimpleTransientPopup::Ondismiss",this);
wxPopupTransientwindow::Ondismiss();
m_bGotItClick = false;
}
}
PS:我是 wxWidgets 的新手
解决方法
通过覆盖“wxPopupTransientWindow::Dismiss()”,我可以在单击按钮时关闭弹出窗口。
void SimpleTransientPopup::Dismiss()
{
if (m_bGotItClick) {
wxLogMessage("%p SimpleTransientPopup::Dismiss",this);
wxPopupTransientWindow::Dismiss();
m_bGotItClick = false;
}
}