Sizer do not work  [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.
FTC
Earned a small fee
Earned a small fee
Posts: 17
Joined: Tue Dec 15, 2009 10:00 am

Sizer do not work

Postby FTC » Tue Dec 15, 2009 10:16 am

Hi,

I just started with wxWidgets and now I am trying to implement sizers, like it is described here:
http://zetcode.com/tutorials/wxwidgetst ... anagement/

But, it does not work like described there. I e.g. use this code:

Code: Select all

   wxMenuBar * menubar = new wxMenuBar;
  wxMenu *file = new wxMenu;

  SetMenuBar(menubar);

  wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);

  wxTextCtrl *display = new wxTextCtrl(this, -1, wxT(""), wxPoint(-1, -1),
     wxSize(-1, -1), wxTE_RIGHT);

  sizer->Add(display, 0, wxEXPAND | wxTOP | wxBOTTOM, 4);
  wxGridSizer *gs = new wxGridSizer(4, 4, 3, 3);

  gs->Add(new wxButton(this, -1, wxT("Cls")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("Bck")), 0, wxEXPAND);
  gs->Add(new wxStaticText(this, -1, wxT("")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("Close")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("7")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("8")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("9")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("/")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("4")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("5")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("6")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("*")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("1")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("2")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("3")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("-")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("0")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT(".")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("=")), 0, wxEXPAND);
  gs->Add(new wxButton(this, -1, wxT("+")), 0, wxEXPAND);

  sizer->Add(gs, 1, wxEXPAND);
  SetSizer(sizer);
  SetMinSize(wxSize(270, 220));


But all the Buttons are in one place at the top left of the Frame. They are not aligned as described in the tutorial. I haven't found anything in the changes.txt. Has there been an internal change regarding the sizers? Or do you see a different error?

greetings

DavidHart
Site Admin
Site Admin
Posts: 3776
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Postby DavidHart » Tue Dec 15, 2009 12:24 pm

Hi,

(I moved this from the wxCode forum, which is for discussion of the projects stored at http://wxcode.sourceforge.net/index.php)

One thing that may be causing the problem is that you're inserting 20 items into a 4x4 grid ;) . wx2.9 is less tolerant of grid overpopulation than previous versions.

Otherwise, try doing sizer->Layout(); at the end of that code. Also, what happens if you manually resize the app with the mouse? If the contents suddenly become correctly laid out, that's usually a sign of a missing Layout().

I haven't found anything in the changes.txt. Has there been an internal change regarding the sizers?
There have been sizer changes in wx2.9, but not that would cause this problem.

Regards,

David

FTC
Earned a small fee
Earned a small fee
Posts: 17
Joined: Tue Dec 15, 2009 10:00 am

Postby FTC » Tue Dec 15, 2009 3:41 pm

Hi,

makeing the sizer a bigger grid does not work, same error.

When I use sizer->setLayout() the window is just grey, not even the "unsorted" items are displayed.
When resizing the window it first "jumps" into a different size, and I cannot scale it below a certain size, though.

I am using wx2.8.10 (because it said latest stable) , should I upgrade?

greetings
Attachments
no_setsize.jpg
no_setsize.jpg (15.05 KiB) Viewed 1651 times

DavidHart
Site Admin
Site Admin
Posts: 3776
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Postby DavidHart » Tue Dec 15, 2009 4:01 pm

Hmm, your code works for me (wxGTK-2.8.10). What platform are you using?

When resizing the window it first "jumps" into a different size, and I cannot scale it below a certain size, though.
Did resizing make the buttons show correctly, though?

I am using wx2.8.10, should I upgrade?
No, 2.8.10 is the current stable version.

FTC
Earned a small fee
Earned a small fee
Posts: 17
Joined: Tue Dec 15, 2009 10:00 am

Postby FTC » Tue Dec 15, 2009 4:05 pm

DavidHart wrote:What platform are you using?

Win XP Sp3, compiled with msys and used with Codeblocks

DavidHart wrote:Did resizing make the buttons show correctly, though?

No, they stay the same way they are.
Last edited by FTC on Tue Dec 15, 2009 4:07 pm, edited 1 time in total.

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

  [SOLVED]

Postby Auria » Tue Dec 15, 2009 4:06 pm

I see you're on Windows; this may not be the cause of the problem, but it's highly recommended to put a panel into your frame, then add everything else (buttons and sizers) to that panel.
"Keyboard not detected. Press F1 to continue"
-- Windows

FTC
Earned a small fee
Earned a small fee
Posts: 17
Joined: Tue Dec 15, 2009 10:00 am

Postby FTC » Tue Dec 15, 2009 4:23 pm

Hi!

Thanks adding a panel works.

greetings


Return to “C++ Development”

Who is online

Users browsing this forum: No registered users and 40 guests