problem with show/hide in nested dialogs Topic is solved

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
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

problem with show/hide in nested dialogs

Post by mael15 »

hi,

in my app i have a settings dialog. in that dialog, there is a button opening a second dialog. while the second dialog is displayed, the first should be hidden, so i use first->Hide().

the problem is, when i call first->Show() after/while destroying the second dialog, the first is also destroyed.

how can this be?

unfortunately, the wxWidgets dialog sample does not work, so i cannot look for an answer there.

thanx for your thoughts!
okurtsev
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jan 25, 2010 3:26 pm
Location: Ukraine, Kiev

Post by okurtsev »

It is complex to understand where and when you call "Show" and what happens without the code.

just in case, may be you need wxWizard? It seems suitable for such purposes.
C++, Win XP-32, Win7-64, WinVista-32, MS VS 2005, 2008, 2010
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 »

thanx,

wxWizard is an option, but i only have one more window to show, so it does not seem the best choice.
JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway »

Hi,

If only 1 dialog is visible at a time, consider using only a single dialog window.

Put each set of controls in its own sizer. So you end up with a top sizer for each set of controls, then put each of these into the main sizer for the dialog.
Then use show/hide on the sizers themselves.
e.g. :

Code: Select all

Dialog1Sizer->Add(... all the controls for the first dialog);
Dialog2Sizer->Add(... all the controls for the second dialog);
TopSizer->Add(Dialog1Sizer);
TopSizer->Add(Dialog2Sizer);
// hides all of dialog 2 controls...
TopSizer->Hide(Dialog2Sizer);
this->SetSizer(TopSizer);
// show only the first dialog...
TopSizer->Layout();
When you want to show the second dialog:

Code: Select all

// Hide dialog 1, and show dialog 2
TopSizer->Hide(Dialog1Sizer);
TopSizer->Show(Dialog2Sizer);
TopSizer->Layout();
Then flip it around when you want to go back to dialog 1.

One advantage is that the controls retain their values if the user switches back to 'dialog' 2 a subsequent time.

Hope that helps,

Jim
OS: Vista SP1, wxWidgets 2.8.7.
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 »

works like a charm, thanx!!!
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

If the topic is solved, please click on "accept" at the top of the post that helped you most to mark the topic as solved and give credits to people who helped you.

Thanks
"Keyboard not detected. Press F1 to continue"
-- Windows
Post Reply