swaping a panel for another?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
frustratedwidgetsguy
In need of some credit
In need of some credit
Posts: 1
Joined: Mon Aug 07, 2017 2:44 am

swaping a panel for another?

Postby frustratedwidgetsguy » Mon Aug 07, 2017 3:12 am

So I have a page set up that has a bunch of different controls on it. I have placed an empty panel on the bottom of the page, but depending on the settings that the user selected, I want different options to appear. So what I want to be able to do is swap that empty panel with a non-empty one.
here is a simple pic to kind of show what I am trying to go for. So how would I be able to do this?

Image http://imgur.com/a/1xNZ5

basically in code what I am doing is this.

Code: Select all

// pointers in the class to the controls/panels
wxPanel* swappanel;
wxCheckBox* buttonA;
// etc...

void selectPanel()
{
   if( options A )
   {
      swappanel = LoadPanel( ...  "optionApanel")  // I stored the data in an xml resource
   };
   else if( options B )
   {
      swappanel = LoadPanel( ...  "optionBpanel")
   }
   else
   {
      swappanel = LoadPanel( ...  "optionCpanel")
   }
}


right now the code will load the panel, but it will not be in the correct position and is not selectable at all. it will be in the top left corner of the window.

I was searching around and it seems I need to call layout on the window?, but I cannot seem to get that to work.

User avatar
doublemax
Moderator
Moderator
Posts: 11472
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: swaping a panel for another?

Postby doublemax » Mon Aug 07, 2017 5:07 am

Create all different panels at once, put them in a wxSimplebook, then use wxBookCtrlBase::SetSelection() to control which page is visible.
http://docs.wxwidgets.org/trunk/classwx_simplebook.html
Use the source, Luke!

Nunki
Earned some good credits
Earned some good credits
Posts: 134
Joined: Fri Sep 14, 2012 8:26 am
Location: Kontich, Belgium
Contact:

Re: swaping a panel for another?

Postby Nunki » Sat Aug 12, 2017 9:16 am

Hi Fru-

I create my dialogs with DialogBlocks and use the XRC layout, but that doesn't matter, the idea's the same. So I create a dialog and add a wxPanel on it with a horzontal or vertical sizer in it.

First I get a handle to that panel and its sizer

Code: Select all

 hPanel = XRCCTRL(*this, "ID_PANEL18", wxPanel);
 hSizer = hPanel->GetSizer();


Then if the pointer to the object inside the panel is not NULL, then we have a change between two panels and we detach this window from the sizer to destroy it. ( so we clear the panel from the object currently in it)

Code: Select all

 if (this->hBase != NULL)
   {
    hSizer->Detach(static_cast<wxWindow *>(this->hBase));
    delete this->hBase;
    this->hBase = NULL;
   }


Then based upon what object to show now, usually an if then else or switch construct, I create the object telling it hPanel is the parent.

Code: Select all

this->hBase = new tcBaseFO(hPanel,0,0,nWidth,nHeight,TBAR_ICN_NEW|TBAR_ICN_CHANGE|TBAR_ICN_REM|TBAR_ICN_MOVEUP|TBAR_ICN_MOVEDOWN|TBAR_ICN_MOVE,SBAR_NONE);


Then I do some sizing stuff to fill the area with the new object

Code: Select all

       hSizer->Add(this->hBase, 1, wxGROW|wxALL, 0);
       this->hBase->Layout();
       hPanel->Layout();


Last but not least

Code: Select all

 hPanel->Layout();
 this->Fit();
 Refresh();


This is roughly the way I use to achieve the thing you need. I hope this helps you on your way, good luck.

Regards,
Nunki


Return to “C++ Development”

Who is online

Users browsing this forum: No registered users and 2 guests