wxwidgets resize sizers after hiding/showing child controls
I have an wxWindow. Inside there I've got a wxBoxSize (Vertical). The sizer has 3 child controls.
I want to be able to hide one of the three child controls, and have the sizer and its parent automaticly resize. For example when I hide one child control of the sizer, the window decreases by 200 pixels.
Right now my method of showing hiding certain contr开发者_开发问答ols, and resizing the window looks like this: (Hardcoded, fugly)
void GenUIAanleverOptionsDialog::OnToggleButtonShowLabels( wxCommandEvent& event )
{
if(this->btnShowLabels->GetValue())
{
this->pnlInfoLabels->Show(true);
this->SetSize(this->GetSize().GetWidth(), 573);
}
else
{
this->pnlInfoLabels->Show(false);
this->SetSize(this->GetSize().GetWidth(), 294);
}
}
The solution I found working for me was to Hide/Show the Sizer that contained the panel. After changing the visibility of the Sizer, a call to the Sizer's method Layout() was necassary.
That however did not also adjust the position of the parent window, so a call to the wxWindow's Fit() method was necassary aswell.
Final code:
void GenUIStatusAanleverFrame::OnToggleButtonShowLabels( wxCommandEvent& event )
{
if(this->btnShowLabels->GetValue())
{
this->sizerInfoLabels->Show(true);
this->sizerOverview->Layout();
}
else
{
this->sizerInfoLabels->Show(false);
this->sizerOverview->Layout();
}
this->Fit();
}
精彩评论