wxBoxSizer question

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
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3320
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

wxBoxSizer question

Post by ONEEYEMAN » Fri Jan 04, 2013 7:18 am

Hi, ALL,
In my program I need to have following layout:
------------------------------------------------------------------------------
main_panel

button_1 <space> button_2

panel_1 (visible) panel_2 (hidden)

empty grid | empty grid
(4 columns | (7 columns
0 rows) | 2 rows)
------------------------------------------------------------------------------

Clicking the buttons is switching the view between panels.

Here is my code:

Code: Select all

wxBoxSizer *mainSizer = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer *vertical = new wxBoxSizer( wxVERTICAL );
wxBoxSizer *top = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer *panels = new wxBoxSizer( wxVERTICAL );
m_panelSizer = new wxBoxSizer( wxHORIZONTAL );
mainSizer->Add( 5, 5, 0, wxEXPAND, 0 );
vertical->Add( 5, 5, 0, wxEXPAND, 0 );
top->Add( button_1, 0, wxEXPAND, 0 );
top->AddStretchSpacer();
top->Add( button_2, 0, wxEXPAND, 0 );
vertical->Add( top );
vertical->Add( 5, 5, 0, wxEXPAND, 0 );
m_panelSizer->Add( panel_1, 0, wxEXPAND, 0 );
m_panelSizer->Add( panel_2, 0, wxEXPAND, 0 );
panels->Add( m_panelSizer, 0, wxEXPAND, 0 );
vertical->Add( panels, 0, wxEXPAND, 0 );
vertical->Add( 5, 5, 0, wxEXPAND, 0 );
mainSizer->Add( vertical, 0, wxEXPAND, 0 );
SetSizer( mainSizer );
Layout();
panel_2->Hide();
And the button_2 click handler:

Code: Select all

panel_1->Hide();
panel_2->Show();
m_panelSizer->Layout();
Now the problem:
The main panel shows up correctly. However because the width of panel_1 is smaller than panel_2 and the height of panel_1 is smaller than panel_2, when I click the button to display the panel_2 I see scrollbars and the grid in the panel_2 is not 7x2, but rather 4x1.

Question:
How do I make the code display the second panel with full grid? I don't want to see scrollbars, I want to see 7x2 grid.
I am calling Layout() on the button click and I'm hiding the second panel after Layout().

Thank you.

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

Re: wxBoxSizer question

Post by doublemax » Fri Jan 04, 2013 12:16 pm

Screenshots please.
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3320
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxBoxSizer question

Post by ONEEYEMAN » Fri Jan 04, 2013 10:20 pm

doublemax,

Attached.

Thank you.

[EDIT]
P.S.: It would be also nice to get rid of the white space in the top grid area, but I can live with that for now.
[/EDIT]
Attachments
panel2.png
Panel2 visible
panel2.png (17.26 KiB) Viewed 1930 times
panel1.png
Panel1 visible
panel1.png (16.39 KiB) Viewed 1930 times

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

Re: wxBoxSizer question

Post by doublemax » Sat Jan 05, 2013 1:00 pm

I'm still not sure how it's supposed to look when it's correct. Is this a problem with re-layout (only when you switch between the two views), or is the layout always wrong?

It's a little strange that in your sizer code, the "proportion" value is always 0. Is there no control that is supposed to grow/shrink when the frame size changes?
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3320
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxBoxSizer question

Post by ONEEYEMAN » Sun Jan 06, 2013 3:00 am

doublemax,
It looks like the second panel gets it's max size from the first panel. They have the same width and approximately the same height. Therefore the grid on the second panel is not sized correctly and I see the scroll bars.

What I want to see is: first panel is OK, but second panel should take all space available on the right and at the bottom so that the grid will be fully visible.

About the proportion: no need to grow/shrink on the frame re-size. It's only grids.

Maybe all I need is to put each panel in it's own sizer?

Thank you.

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: wxBoxSizer question

Post by Auria » Sun Jan 06, 2013 3:43 pm

I'm not sure from your code which panel contains the wxGrid. But when adding the grid to the sizer (or the grid's parent), set proportion to 1 and add flag wxEXPAND (see the documentation of Add to known which parameter is which)
"Keyboard not detected. Press F1 to continue"
-- Windows

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3320
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxBoxSizer question

Post by ONEEYEMAN » Sun Jan 06, 2013 8:41 pm

Auria,
Both panels contains grid.
It just the first panel's grid is much less space than the second panel's grid. And hence when the view is switched the second grid is not fully visible.

I will try you suggestion and report back.

Thank you.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3320
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxBoxSizer question

Post by ONEEYEMAN » Sat Jan 12, 2013 9:00 am

Auria,
I tried adding both panels with proportion = 1 and flag = wxEXPAND, but got exactly the same results.
Size of the second panel is the same as the size of the first one. And since the latter is much-much smaller, I see scroll bars on the second panel's grid.

Any other idea?

Thank you.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3320
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxBoxSizer question

Post by ONEEYEMAN » Sat Jan 12, 2013 9:18 am

Even using proportion = 1 for the second panel only gives the same results.

Thank you.

P.S.: This is on Windows 2.9.4.

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

Re: wxBoxSizer question

Post by doublemax » Sat Jan 12, 2013 10:51 am

Try to strip down the code as much as possible and create a minimal compilable sample that shows the problem.
Use the source, Luke!

Post Reply