sizers and panel Topic is solved

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
Rachel
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Jun 18, 2011 11:37 pm

sizers and panel

Post by Rachel » Sat Jun 25, 2011 2:49 pm

I have some problems with sizer, perhaps you can help.

I'm using wxwidgets and my GUI is almost done. But now I'm using wxRESIZE_BORDER from the properties of my frame to change the size if necessary...
I have 3 buttons on my GUI which should align on the right with resizing the frame and a wxgrid which should expand.

I did someting like

void frame::frameSize(wxSizeEvent& event)
{
now I want to use sizers, but first problem: my panel has now a static size
}

User avatar
tierra
Site Admin
Site Admin
Posts: 1342
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: sizers and panel

Post by tierra » Sat Jun 25, 2011 6:45 pm

If, by chance, your right-aligned buttons happen to standard dialog buttons (OK, Cancel, Save, Apply, Yes, No, Help, etc), you should just use a wxStdDialogButtonSizer rather than using a wxGridSizer (please be clear about whether you are using wxGrid or wxGridSizer by the way, there's a big difference, and both are possible with what you described).

If you are saying that by setting a wxSizeEvent handler for the frame, your child windows no longer perform layout, try calling event.Skip() in your frameSize() method. This will allow wxWidgets to continue processing size events generated for the frame.

Rachel
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Jun 18, 2011 11:37 pm

Re: sizers and panel

Post by Rachel » Sat Jun 25, 2011 11:04 pm

i tried now this (in CreateGUIControls() ) :

wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *sizerp = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *sizerv = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *sizerh = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *sizert = new wxBoxSizer(wxHORIZONTAL);

sizerp->Add(new wxPanel(WxPanel2, -1));
sizer->Add(sizerp, 1, wxEXPAND);

sizerv->Add(WxButton1);
sizer->Add(sizerv, 0, wxALIGN_RIGHT | wxALIGN_BOTTOM | wxBOTTOM| wxRIGHT , 20);

sizerh->Add(WxButton2);
sizer->Add(sizerh, 0, wxALIGN_RIGHT |wxALIGN_TOP | wxRIGHT | wxTOP, 20);

sizert->Add(WxButton3);
sizer->Add(sizert, 0, wxALIGN_TOP | wxALIGN_RIGHT | wxTOP| wxRIGHT, 20);

WxPanel2->SetSizer(sizer);

but buttons 1,2,3 are always shown together and not button 1 at the bottom and buttons 2,3 at the top. why doesn't it work like that?

Furthermore I have a grid with static box around, which should expand with expanding the frame, but I'm not sure how? Do you have some advice?

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Re: sizers and panel

Post by briceandre » Sun Jun 26, 2011 6:06 am

Putting a single window in a sizer is not really usefull. So, I don't think p,v,h,t sizers are necessary.

From reading your code, I would expect a layout where all elements are layout in column with panel at the top, then button 1, 2 and 3. Is it what you want ? If not, could you tell what you would expect ?

Rachel
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Jun 18, 2011 11:37 pm

Re: sizers and panel

Post by Rachel » Sun Jun 26, 2011 7:51 pm

Oke, I left now the part out with the panel in the sizerp. I just wanted the panel to fit in the frame after resizing..

At the moment all buttons are shown on the rigth, top of the window. But I want button 1 in the right, top and button 2,3 in the right, bottom.. it doesn't work like that...

Furthermore I have a wxgrid with a defautl size, but I want it to expand, when the frame expands until the scrollbars of the wxgrid are not necessary anymore..

You realize I'm not really used to sizers, and layout..

User avatar
tierra
Site Admin
Site Admin
Posts: 1342
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: sizers and panel

Post by tierra » Sun Jun 26, 2011 9:02 pm

Maybe you could put together a graphic of some kind to show us what it is you're trying to do, because I'm still confused about what the layout is that you're trying to go through and what part of sizers you don't understand.

There's also an incredibly helpful tutorial on sizers here: http://neume.sourceforge.net/sizerdemo/

Rachel
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Jun 18, 2011 11:37 pm

Re: sizers and panel

Post by Rachel » Sun Jun 26, 2011 9:36 pm

Sorry that I couldn't explain it right away, here a picture.
with resizing:
button 1,2 should align at top, right
button 3 bottom, right
grid should stay in the position on the left and top and expand to the right and bottom (until scrolling isn't necessary anymore)
so, thanks
Attachments
GUI.JPG
GUI.JPG (32.35 KiB) Viewed 7343 times

Rachel
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Jun 18, 2011 11:37 pm

Re: sizers and panel

Post by Rachel » Tue Jul 05, 2011 5:26 pm

Oke we can delete Button 3, but can anybody help me with the resizeproblem of the wxgrid?
it should stay in postition left and top and expand to rigth and bottom until scrolling is unnecessary (with a distance of 25 for expample to the borders)..
Thanks

ouch67
Earned some good credits
Earned some good credits
Posts: 134
Joined: Sun Mar 23, 2008 12:09 am

Re: sizers and panel

Post by ouch67 » Tue Jul 05, 2011 7:52 pm

flexgrid sizer's is pretty much all I ever use because you have more control over them.

you can then make your grid change with window size with the growablecols and growablerows functions.

Rachel
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Jun 18, 2011 11:37 pm

Re: sizers and panel

Post by Rachel » Tue Jul 05, 2011 8:50 pm

I'm using wxwidgets.
I don't find anything about growablecols and growablerows functions.
I thought i can do something like:

int x = frame->getheigth
x = x-25
grid->setwidth(x)

inside the event of resizing the frame:
but I only found event onsize, but when I use this, the Panel has a random size and doesn't fit the frame...

ouch67
Earned some good credits
Earned some good credits
Posts: 134
Joined: Sun Mar 23, 2008 12:09 am

Re: sizers and panel

Post by ouch67 » Wed Jul 06, 2011 3:14 pm

The growable functions are part of flexgridsizer. Because with that one the grid doesn't try to equalize the size of each field. If you want something to dynamically change size then this sizer is pretty much what you have to use. The layout your trying to achieve can be done with only 2 of these sizers because of their adaptability as well. It's why I use them almost exclusively in my designs.

After your panel add a flexgridsizer to as a base. Set it to be 2 columns. Create your wxgrid, set it to expand. then create another sizer for your buttons, this will be in column 1. (columns and rows start at 0) set the columns of that to 0. then add your 3 buttons to this sizer. set the vertical alignment of the last button to bottom. use the growablecols/row functions to set row 0 and column 0 for the first sizer and then set row 3 column 0 for the last one.

When done the wxgrid should expand with the available space on the left, 2 buttons will be at the top with one sticking to the bottom. You can set the minsize of the wxgrid to keep it from being able to collapse too far.

Rachel
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Jun 18, 2011 11:37 pm

Re: sizers and panel

Post by Rachel » Wed Jul 06, 2011 11:33 pm

Thanks for the advice with the flexgridsize!
I'm quite sure I didn't do it the smartest way, but I used the sizers of my buttons I already had and the felxgridsizer.
If somebody is interested:

wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *sizerv = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *sizert = new wxBoxSizer(wxHORIZONTAL);

sizerv->Add(WxButton1);
sizer->Add(sizerv, 0, wxALIGN_RIGHT | wxALIGN_TOP | wxTOP| wxRIGHT ,80);

sizert->Add(WxButton2);
sizer->Add(sizert, 0, wxALIGN_TOP | wxALIGN_RIGHT | wxTOP| wxRIGHT |wxBOTTOM, 80);

wxFlexGridSizer *fgs = new wxFlexGridSizer(1,2, 50, 0);
fgs->Add(WxGrid, 1, wxEXPAND);
fgs->AddGrowableRow(1, 1);
fgs->AddGrowableCol(0, 1);
sizer->Add(fgs, 1, wxALL | wxEXPAND, 30);
WxPanel->SetSizer(sizer);

Post Reply