How to make this layout work?

13 views
Skip to first unread message

Igor Korot

unread,
Sep 26, 2012, 2:45:03 AM9/26/12
to wx-u...@googlegroups.com
Hi, ALL,
I have a wxPanel-derived class whose constructor looks like this:

m_label = new wxStaticText( this, wxID_ANY, "Please enter owner names." );
m_scrolled = new wxScrolledWindow( this );
m_label->SetFont( m_label->GetFont().Bold() );
wxSizer *mainSizer = new wxBoxSizer( wxHORIZONTAL );
wxSizer *secondSizer = new wxBoxSizer( wxVERTICAL );
wxSizer *controls = new wxBoxSizer( wxVERTICAL );
wxSizer *editors = new wxBoxSizer( wxVERTICAL );
mainSizer->Add( 5, 5, 0, wxEXPAND, 0 );
secondSizer->Add( 5, 5, 0, wxEXPAND, 0 );
controls->Add( m_label, 0, wxEXPAND, 0 );
controls->Add( 5, 5, 0, wxEXPAND, 0 );
m_owners = new wxTextCtrl[owners];
for( int i = 0; i < owners; i++ )
{
m_owners[i].Create( m_scrolled, wxID_ANY );
editors->Add( &m_owners[i], 0, wxEXPAND, 0 );
editors->Add( 5, 20, wxEXPAND, 0 );
}
m_scrolled->SetSizer( editors );
m_scrolled->FitInside();
m_scrolled->SetScrollRate( 5, 5 );
controls->Add( m_scrolled, 1, wxEXPAND, 0 );
secondSizer->Add( controls, 0, wxEXPAND, 0 );
secondSizer->Add( 5, 5, 0, wxEXPAND, 0 );
mainSizer->Add( secondSizer, 0, wxEXPAND, 0 );
mainSizer->Add( 5, 5, 0, wxEXPAND, 0 );
SetSizerAndFit( mainSizer );

However with this code all I see is very small scrolled window which
is sized around the
text control.

What I want to see is scrolled window that is stretched on the whole
area of the panel.
Screenshot of running the code attached.

What am I doing wrong?

Thank you.
screenshot.png

Catalin

unread,
Sep 26, 2012, 3:47:37 AM9/26/12
to wx-u...@googlegroups.com

From: Igor Korot <ikorot01@>
Sent: Wednesday, 26 September 2012, 9:45

You probably need

    secondSizer->Add( controls, 1, wxEXPAND, 0 );
    mainSizer->Add( secondSizer, 1, wxEXPAND, 0 );
see the value of `proportion` argument.

Regards,
C

p.s. Could you remove the irrelevant parts from such snippets?  Like (but not only) the calls that add spacers, set some font etc. It'd make the code much easier to read if it is cut in half.

p.s.2  I'm surprised your code does not crash when you exit the app. Apparently the text controls are deleted once when m_owners is destroyed and again when their parent is.

Igor Korot

unread,
Sep 26, 2012, 4:21:59 AM9/26/12
to wx-u...@googlegroups.com
Hi,
Well this does not help.

Any other ideas?

Thank you.

>
> Regards,
> C
>
> p.s. Could you remove the irrelevant parts from such snippets? Like (but
> not only) the calls that add spacers, set some font etc. It'd make the code
> much easier to read if it is cut in half.
>
> p.s.2 I'm surprised your code does not crash when you exit the app.
> Apparently the text controls are deleted once when m_owners is destroyed and
> again when their parent is.

No idea.
But the pointer is destroyed only once.

>
> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users

Julian Smart

unread,
Sep 26, 2012, 4:25:01 AM9/26/12
to wx-u...@googlegroups.com
Yes. Use a tool to generate the sizers; you can experiment easily with it.

:-)

Regards,

Julian

Igor Korot

unread,
Sep 26, 2012, 3:37:48 PM9/26/12
to wx-u...@googlegroups.com
Julian,
I tried to follow you suggestion.
I have wxGlade installed and tried to recreate the layout I'm looking for.
It did look nice in the designer, but in the Preview it looked the same as in
my screenshot.
So what I did was being in the Preview more resized the panel and achieve
what I wanted.

The problem is that the main panel is part of the notebook, which is part
of the wizard. And it's not the first page of the notebook. So I can't manually
resize the panel.

I tried to get the size of the first page of the notebook and pass it
to this one
but that didn't help.

However, if I call:

SetSizer( mainSizer );
Layout();

instead of

SetSizerAndFit( mainSizer );

everything seems to work OK.

Problem solved.

Thank you.

>
> Regards,
>
> Julian
Reply all
Reply to author
Forward
0 new messages