Help with simpler minimal sizer problem. 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
webmasterpdx
Knows some wx things
Knows some wx things
Posts: 27
Joined: Thu Jun 25, 2009 2:43 am
Location: Portland, Oregon
Contact:

Help with simpler minimal sizer problem.

Post by webmasterpdx »

I posted another thread that I closed out because I got the answers I needed and figured I only needed to use one sizer and this is where I'm stuck right now. This problem can be illustrated in a much simpler example....

I have several absolutely positioned panels in a wxDialog. There is one on the bottom right where I want to place some buttons and since I figure it's stupid to have to absolutely position buttons on a panel, a sizer should be able to handle that nicely. I tried it and the sizer seems to want to place the buttons on top of one another.

Here is what the code does.

panel = new wxPanel(... // Creates with set pos and size.

bsizer = new wxBoxSizer(wxHORIZONTAL); // simple sizer
bsizer->SetDimension(... // Set to same size as panel

b1 = new wxButton(panel,... // buttons in panel
b2 = new wxButton(panel,...
b3 = new wxButton(panel,....

bsizer->Add(b1,0,wxALIGN_RIGHT); // try to align right
bsizer->Add(b2,0,wxALIGN_RIGHT);
bsizer->Add)b3,0,wxALIGN_RIGHT);

panel->SetSizer(bsizer);

Thats it...the ...'s above are just standard other args to those calls (nothing unusual). Note I called SetDimension to force the sizer to be the same size as the panel. Now, I should be able to just call Add and it should place the buttons next to one another. No matter what I do, it seems to place the buttons not only on top of one another, but aligned to the left, when I explicitly tell it to align them to the right!!!!

Anyone seen this problem before?

Thanks
-Donald
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

understanding sizers is a science of its own ;)

The wxALIGN_RIGHT flag only applies for items inside a vertical boxsizer. Check this site, it should help understanding sizers a bit better;
http://neume.sourceforge.net/sizerdemo/

In your case, do a bsizer->AddStretchSpacer() before adding the first button. Then the buttons will be right-aligned.

But i've never seen a horizontal boxsizer putting items on top of each other.
Use the source, Luke!
jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche »

A good way to use sizers is to give a try to wxFormBuilder. It's an application that allow you to create your gui as a WYSIWYG editor. It's very helpfull for me, who don't like to waste time to create gui. I think wxDesigner can do this also, but I didn't try it.

For me, it was the best tool to learn about sizers.
Jérémie
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Components on top of each other is often a parenting issue. i.e. you added your children to the panel, but then added them to sizer0 which was assigned to the frame (mismatch there, if the components inside ther sizer are on a panel, the sizer must be on the same panel and can't be on the frame)
"Keyboard not detected. Press F1 to continue"
-- Windows
webmasterpdx
Knows some wx things
Knows some wx things
Posts: 27
Joined: Thu Jun 25, 2009 2:43 am
Location: Portland, Oregon
Contact:

Post by webmasterpdx »

I'd actually seen that demo Doublemax...and understood it, but it's significant if Alignment only works on vertical sizers.

wxFormDesigner...I use wxDevC++ which has similar controls. I don't think they do much with sizers....I'll have to check that...

Thx
-D
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

I'd actually seen that demo Doublemax...and understood it, but it's significant if Alignment only works on vertical sizers.
that's not the point.

Alignment options only apply in the direction that is not the direction of the sizer.

For horizontal sizers, these alignment options are valid:
wxALIGN_TOP
wxALIGN_BOTTOM
wxALIGN_CENTER_VERTICAL

For vertical sizers, these:
wxALIGN_LEFT
wxALIGN_RIGHT
wxALIGN_CENTER_HORIZONTAL

Take this image of a vertical sizer from the sizer demo:
Image

The "tiny button" is less wide that the total width of the sizer. Here you can decide what to do with the button, left-align, right-align, center or stretch to fill the whole space. A top or bottom alignment wouldn't make sense for this button.
Use the source, Luke!
webmasterpdx
Knows some wx things
Knows some wx things
Posts: 27
Joined: Thu Jun 25, 2009 2:43 am
Location: Portland, Oregon
Contact:

I understand...

Post by webmasterpdx »

...about the sizers.

wxDevC++ handles sizers in the forms, but the part I'm doing is programmatic. I'm creating a wizard from a dialog full of panels.

wxWizard is not to my liking and doesn't have form support....so I had to write my own.

Actually, I found it to be less trouble to not use sizers at all and use absolutes. Works perfectly. Rock solid.

Thanks all.
I do understand sizers a lot better now though for future reference.

Thx
-D
Post Reply