How to change panel content on fly?

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.
Post Reply
Jacek Poplawski
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 20, 2011 12:03 pm

How to change panel content on fly?

Post by Jacek Poplawski »

I have a frame with multiple panels inside.

One panel contains wxChoice.
Another panel contains set of wxSliders.

When user will select another thing by clicking wxChoice, number of sliders should change.

For instance, when user will select first choice, there should be 9 sliders visible, but when user will select second choice, there should be 12 sliders visible.

I coded it this way:
1) when user will change choice, I remove sliders from Sizer with Detach
2) I also destroy them with delete
3) then I add new sliders to Sizer
4) then I call Layout() on panel

I tried different combinations of Layout(), Fit() on panel and parent windows.

But I am never able to make the panel change its size after number or sliders will change.

So when there is 9 sliders at the beginning and I create 12 sliders - the window size stay the same.

What is recommended way to change the panel content on fly and how to make window fit new size?
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Hi,

who is the parent of the panel? Calling Layout() on the panel itself is good but likely to get the effect you want you will need to move up the hierarchy and deal with the parent of the panel - possiblt the top-level parent
"Keyboard not detected. Press F1 to continue"
-- Windows
Jacek Poplawski
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 20, 2011 12:03 pm

Post by Jacek Poplawski »

Nothing happens when I call Layout() or Fit() on parents.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

What parents?

Usually you need to call Layout() then Fit() the top-level frame
"Keyboard not detected. Press F1 to continue"
-- Windows
Jacek Poplawski
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 20, 2011 12:03 pm

Post by Jacek Poplawski »

Looks like I have to create separate test case to analyze that.
RainRat
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Thu Jan 06, 2011 11:26 pm

Post by RainRat »

It should be easier to just hide/show the wxSliders instead of deleting and recreating them.

You may also need to try Refresh() after using Layout(). These things take a little effort, experience and trial and error to get correct.
msksharath
In need of some credit
In need of some credit
Posts: 8
Joined: Wed Jun 29, 2011 11:33 am

Re: How to change panel content on fly?

Post by msksharath »

use wxCardSizer.

There is an AddCard function to which you can add your new GUI(as a panel or any control).
Then you can call panel or GUI of your choice by ShowCard(int).
Go for this if GUI is so complicated for show/hide.

Else go for show/hide.
Post Reply