Hard time with sizers. 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
vdumont
I live to help wx-kind
I live to help wx-kind
Posts: 155
Joined: Wed Mar 29, 2006 7:13 pm
Location: QC,Canada

Hard time with sizers.

Post by vdumont »

Hi, I am trying to have a big wxGLCanvas on the left, and a TreeCtrl on the right

The result is that the glCanvas is splitted 50/50 with the TreeCtrl even though I specify their sizes.

Code: Select all

    
    wxSize sizeTreeview(225,450);
    wxSize sizeGlCanvas(640, 526);
    
     treeview = new wxTreeCtrl(this, ID_TREEVIEW, wxDefaultPosition, sizeTreeview, wxTR_HAS_BUTTONS | wxTR_SINGLE);
    m_canvas =  new GLCanvas(this, wxID_ANY,wxDefaultPosition, sizeGlCanvas);
   
    wxSizer *sizer1 = new wxBoxSizer(wxHORIZONTAL); 
    sizer1->Add(m_canvas, 1, wxEXPAND, 0); 
    sizer1->Add(treeview, 1, wxEXPAND, 0);
    SetSizer(sizer1); 

I've been trying to fix this for an hour but I always end up with a 50/50 layout :(
alexcoppo
Knows some wx things
Knows some wx things
Posts: 37
Joined: Mon Sep 06, 2004 8:56 am
Location: Italy
Contact:

Post by alexcoppo »

When you Add() widgets, you specify a weight for expansion (the 1 in the call) equal for both items, so they occupy each 50% (1 / (1 + 1)). You have to specify different weights; e.g. setting 1 and 2 would give 1/3 to the first widget and 2/3 to the other one.

Bye!!!!!!!
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

The second paramter of wxSizer::Add is the proportion,
if you set both to 1, its 50/50.
http://wxwidgets.org/manuals/2.6.2/wx_w ... wxsizeradd

You might should think about using wxFlexGridSizer, cause it offers more flexablity.

phlox
vdumont
I live to help wx-kind
I live to help wx-kind
Posts: 155
Joined: Wed Mar 29, 2006 7:13 pm
Location: QC,Canada

Post by vdumont »

Thanks to both of you. :)
Post Reply