Hi,

I followed all your comments about the code and it worked without using
show/hide functions.

Thank you very much!
Aida

2011/10/11 Xavier Planes <xavier.pla...@upf.edu>

> Hi Aida,
>
>        You need to be carefully when using a sizer and the functions
> Detach() or Remove().Remove() will remove the child from the sizer and
> destroys it if it’s a sizer or spacer.
>        http://docs.wxwidgets.org/2.8.10/wx_wxsizer.html#wxsizerremove
>        http://docs.wxwidgets.org/2.8.10/wx_wxsizer.html#wxsizerdetach
>
>        In your example, these lines will destroy the "SUR" labels but not
> the "Standard SUR" labels (m_label5 and m_label6):
>         m_grid_sizer2->Detach(m_label3);
>        m_grid_sizer2->Detach(m_label4);
>        m_label3->Destroy();
>        m_label4->Destroy();
>
>         In the next piece of code m_grid_sizer2 will be detached from
> m_sizer3 but it will not be destroyed because when calling Remove() the
> sizer m_grid_sizer2 is not a child of m_sizer3:
>        m_sizer3->Detach(m_grid_sizer2);
>        m_sizer3->Remove(m_grid_sizer2);
>
>        Finally m_sizer3 will be detached:
>        m_sizer2->Detach(m_sizer3);
>        m_sizer2->Remove(m_sizer3);
>
>        At the end, the labels m_label5 and m_label6 are not destroyed and
> will be floating in the parent window because the sizer where they were
> inserted (m_grid_sizer2) has been detached from the main sizer (m_sizer2).
>
>        I recommend you to better use show/hide functions instead of
> destroying the labels/sizers. This will simplify the code. Sometimes we add
> a checkbox called "Advanced" to show/hide some advanced controls on the
> window.
>
> Best,
> Xavi
>
>
> From: Aida Ninyerola [mailto:aida.ninyer...@gmail.com]
> Sent: lunes, 10 de octubre de 2011 15:11
> To: gimias-developers@lists.sourceforge.net
> Subject: [Gimias-developers] panel widget
>
> Hi,
>
> During our process we create some controls in order to show the achieved
> results.
>
>         wxStaticBox* m_sizer3_staticbox = new wxStaticBox(this, -1,
> wxT("Results of Quantificaction:"));
>         m_sizer3 = new wxStaticBoxSizer(m_sizer3_staticbox, wxVERTICAL);
>         m_grid_sizer2 = new wxFlexGridSizer(2, 2, 0, 0);
>         m_label3 = new wxStaticText(this, wxID_ANY, wxT("SUR " + nameResult
> + ":\t"),wxDefaultPosition, wxDefaultSize,
> wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
>         m_label3->SetFont(wxFont(8, wxDEFAULT, wxNORMAL, wxBOLD));
>         m_label4 = new wxStaticText(this, wxID_ANY,
> wxT(wxString::Format("%.5f", numResult )),wxDefaultPosition, wxDefaultSize,
> wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL);
>         m_label5 = new wxStaticText(this, wxID_ANY, wxT("Standard SUR
> :\t"),wxDefaultPosition, wxDefaultSize,
> wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
>         m_label5->SetFont(wxFont(8, wxDEFAULT, wxNORMAL, wxBOLD));
>         m_label6 = new wxStaticText(this, wxID_ANY,
> wxT(wxString::Format("%.5f", StandardResult )),wxDefaultPosition,
> wxDefaultSize, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL);
>         m_grid_sizer2->Add(m_label3, 0,wxEXPAND|wxALL,5);
>         m_grid_sizer2->Add(m_label4, 0,wxEXPAND|wxALL,5);
>         m_grid_sizer2->Add(m_label5, 0,wxEXPAND|wxALL,5);
>         m_grid_sizer2->Add(m_label6, 0,wxEXPAND|wxALL,5);
>         m_sizer3->Add(m_grid_sizer2, 0, wxALL|wxEXPAND, 5);
>         m_sizer2->Add(m_sizer3, 0, wxALL|wxEXPAND, 5);
>
>         // Resize this
>         // Cast a resize event
>         wxSizeEvent resEvent(this->GetBestSize(), this->GetId());
>         resEvent.SetEventObject(this);
>         this->GetEventHandler()->ProcessEvent(resEvent);
>         this->Refresh();
>
> At some point we need to destroy this controls. We have this code in order
> to achieve this
>
>         //Remove static texts
>         m_grid_sizer2->Detach(m_label3);
>         m_grid_sizer2->Detach(m_label4);
>         m_label3->Destroy();
>         m_label4->Destroy();
>
>         //Remove grid sizer
>         m_sizer3->Detach(m_grid_sizer2);
>         m_sizer3->Remove(m_grid_sizer2);
>
>         //Remove sizer 3
>         m_sizer3->Show(false);
>         m_sizer2->Detach(m_sizer3);
>         m_sizer2->Remove(m_sizer3);
>         GetSizer()->Layout();
>         GetSizer()->Fit(this);
>
>         // Resize this
>         // Cast a resize event
>         wxSizeEvent resEvent(this->GetBestSize(), this->GetId());
>         resEvent.SetEventObject(this);
>         this->GetEventHandler()->ProcessEvent(resEvent);
>
> Although the creation works correctly, when we later try to destroy those
> controls, they are not destroyed and other parts of the panel widget are
> eliminated and all the panel widget of the processor stops working
> correctly.
>
> What is being done uncorrectly?
>
> Thank you very much,
> Aida
>
>
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct
_______________________________________________
Gimias-developers mailing list
Gimias-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gimias-developers

Reply via email to